Skip to content

AggregateModel: Cannot add hasOne reference #984

@mkrecek234

Description

@mkrecek234

The recent implementation of AggregateModel does not allow to add a hasOne reference (or inherit it from the source model).
Steps to replicate:

 $aggregateModel =  new \Atk4\Data\Model\AggregateModel($sourcemodel);
        
        $aggregateModel->hasOne('tax_rule_id', ['model' => [TaxRule::class]]);
        
        $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])'],
        ]);

Expected result:
$targetmodel->ref('tax_rule_id') returns hasOne-linked model.

Result:
Error in vendor/atk4/data/src/Reference.php:224saying TypeError: preg_quote(): Argument #1 ($str) must be of type string, null given

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions