Not a bug Entity relation order doesn't affect when used with defaultWith

Painbaker

Well-known member
Affected version
2.2.3
I'm trying to change order for entity relation that defined in defaultWith and nothing happens.

PHP:
$structure->relations['CustomStylePurchase'] = [
    'entity' => 'CustomStylePurchase:Purchase',
    'type' => self::TO_ONE,
    'conditions' => [
        ['content_type', '=', $structure->contentType],
        ['content_id', '=', '$' . $structure->primaryKey],
    ],
    'order' => ['purchase_date', 'DESC'],
    'primary' => false
];

$structure->defaultWith += ['CustomStylePurchase'];

In this case array key 'order' seems is ignored (the column does not exist)

After deleting relation from defaultWith it works correctly.
I don't understand what prevents the sorting for default relations...
 
Order really only relates to TO_MANY relationships. TO_ONE relationships mean that the relationship you've defined (based on the conditions) can only resolve to one (or zero) rows, thus an order doesn't really make sense.

If you need an order to identify the specific row, it's a TO_MANY relationship and thus wouldn't be possibly to eagerly fetch via defaultWith.
 
Top Bottom