Not a bug Entity hydrate with wrong relation

truonglv

Well-known member
Affected version
2.0.6
When hydrate an relation the entity did not check the conditions so in some cases could make wrong relation.
Eg:

PHP:
Class A ...



$structure->relations['B'] = [

'conditions' => [

[...],

['user_id', '=', \XF::visitor()->user_id]

]

];



$structure->defaultWith = ['B'];

PHP:
class B {
    ...
    $structure->relations['A'] = [...];

    $structure->defaultWith = ['A'];
}

When fetch data from relation B with user_id difference with current visitor so when access A->B could give wrong.
Eg:
PHP:
$em->findOne('...', [
    // other conditions
    'user_id' => 2
], '...');

Expect: A->B is result of current visitor.
Actual: A->B is return of B record not of the current visitor.
 
The conditions in relation order not match with B relation primary key order. So i think it's should not be create relation rather match wrong.
 
Back
Top Bottom