Comments (2)
@mkrecek234 thank you for describing the problem, please add here a small repro code that can be copied and run.
from data.
Please check this sample code based on a MySQL database as described showing the error:
class Account extends Model
{
public $table = 'account';
protected function init(): void
{
parent::init();
$this->addFields(['name', 'fx_rate' => ['type' => 'float']]);
}
}
class Booking extends Model
{
public $table = 'booking';
protected function init(): void
{
parent::init();
$this->addFields(['booking_group', 'value' => ['type' => 'float']]);
$this->hasOne('account_id', ['model' => [Account::class]])->addField('fx_rate');
}
}
public function testAggregate1078(): void
{
$m = new Model($this->db, ['table' => 'account']);
$m->addField('name');
$m->addField('fx_rate', ['type' => 'float']);
$this->createMigrator($m)->create();
$m->import([
['name' => 'Test Account', 'fx_rate' => 1.2],
]);
$m = new Model($this->db, ['table' => 'booking']);
$m->addField('account_id', ['type' => 'integer']);
$m->addField('booking_group');
$m->addField('value', ['type' => 'float']);
$this->createMigrator($m)->create();
$m->import([
['account_id' => 1, 'booking_group' => 'Group1', 'value' => 123],
['account_id' => 1, 'booking_group' => 'Group1', 'value' => 456],
['account_id' => 1, 'booking_group' => 'Group2', 'value' => 789],
]);
$accountModel = new Account($this->db);
$bookingModel = new Booking($this->db);
$bookingAggregate = new AggregateModel($bookingModel);
$bookingAggregate->setGroupBy(['booking_group'], [
'total' => ['expr' => 'sum([value])'], ]);
foreach ($bookingAggregate as $booking) {
echo 'Result: ' . $booking->get('booking_group') . ' | ' . $booking->get('total');
}
echo 'That worked..';
$bookingAggregate = new AggregateModel($bookingModel);
$bookingAggregate->setGroupBy(['booking_group'], [
'total' => ['expr' => 'sum([fx_rate] * [value])'], ]);
foreach ($bookingAggregate as $booking) {
echo 'Result: ' . $booking->get('total');
}
echo 'That did not work..';
}
from data.
Related Issues (20)
- ContainsXxx throw Exception if stored value != null HOT 3
- atk4_money cannot be set to zero
- Why getReference does not work on entity? HOT 1
- Migrator to set foreign keys HOT 2
- Default UserAction 'delete' should have a confirmation message HOT 4
- Model::validateEntityScope() should not fetch/compute any data HOT 2
- Subquery with LIMIT in IN clause should be supported HOT 12
- Does DSQL join support joining from subquery? HOT 1
- Fix all typos HOT 4
- Drop `Model\UserAction::$modifier` property
- Model::set should handle duplicate actual
- Model::dirty not available in Model::HOOK_AFTER_SAVE spot HOT 1
- Monitor if the latest deps are supported in develop using CI
- Bad float/integer input is silently accepted HOT 10
- Set fields to dirty when they are changed within hooks within a model HOT 3
- Narrow seed types more
- SQLite must keep AI incremented after rollback HOT 1
- How to schema->upgrade() ? HOT 3
- Honor backslash if not escaping HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from data.