Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AggregateModel inheriting reference on setGroupBy fields #985

Open
mkrecek234 opened this issue Apr 21, 2022 · 2 comments
Open

AggregateModel inheriting reference on setGroupBy fields #985

mkrecek234 opened this issue Apr 21, 2022 · 2 comments

Comments

@mkrecek234
Copy link
Contributor

mkrecek234 commented Apr 21, 2022

If you create an aggregate Model an group by certain fields which are hasOne references in the source model, it would be convenient to also have/keep those references in the aggregate Model, so if source model has a hasOne reference called 'tax_rule_id':

 $aggregateModel =  new \Atk4\Data\Model\AggregateModel($sourcemodel);
        
$aggregateModel->setGroupBy(['tax_rule_id', 'tax_rate'], [
    'total_gross'                 => ['expr' => 'sum([total_gross])'],
    'total_net'                   => ['expr' => 'sum([total_net])'],
    'total_tax'                   => ['expr' => 'sum([total_tax])'],
]);

foreach ($aggregateModel as $taxposition) {
  $result = $taxposition->ref('tax_rule_id')->get('revenue_account_id');
}

the aggregateModel should then allow $tax_rule_name = $taxposition->ref('tax_rule_id')->getTitle(); for example.

@mvorisek mvorisek changed the title Feature request: AggregateModel inheriting reference on setGroupBy fields AggregateModel inheriting reference on setGroupBy fields Apr 21, 2022
@mvorisek
Copy link
Member

discussion:

image

@mvorisek
Copy link
Member

mvorisek commented Apr 23, 2022

I think no field (nor reference, user action, ...) should be added automatically, because if anything is added automatically:

  • it will select extra data (worsen performance)
  • phpdoc (for hintable) must be always declared manually

However, when such field ())ref, ...) is added to the outer model, the configured properties (class, type, ...) must be inherited as defaults.

@mvorisek mvorisek added the MAJOR label Apr 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants