XF 2.2 What does the "primary" key in entity's relation mean?

asprin

Active member
Just trying to wrap my head around a basic concept in XF2. What's the difference between (1) and (2)?

PHP:
//#1
$structure->relations['Bars'] = [
    'entity'    => 'ABC\DEF:Bar',
    'type'      => self::TO_MANY,
    'conditions' => ['foo_id', '=', '$bar_id'],
    'primary'   => true
];


//#2
$structure->relations['Bars'] = [
    'entity'    => 'ABC\DEF:Bar',
    'type'      => self::TO_MANY,
    'conditions' => ['foo_id', '=', '$bar_id'],
    'primary'   => false
];

And does the meaning of primary=>true change if used on a SELF::TO_ONE relation or does it behave the same as self::TO_MANY
 
Solution
It allows the relation to be looked up in the cache first (since the cache is keyed by primary key), so it is not unnecessarily lazy-loaded. It has no effect on to-many relations either way.
It allows the relation to be looked up in the cache first (since the cache is keyed by primary key), so it is not unnecessarily lazy-loaded. It has no effect on to-many relations either way.
 
Solution
Back
Top Bottom