XF 2.1 Entity relation on composite column not working as expected

asprin

Active member
I've 2 entitles whose table look like the following:

Foo
sys_idtitle
1first title


Bar
sys_idfoouser_idcategory
1145cat1
2187cat1

So, if we apply a composite filter on Bar using foo = 1 AND user_id = 87, I should be getting a single row from Bar, i.e. in this case Bar sys_id = 2 row. This is the expectation.

Now the relations defined on Foo are as follows:

PHP:
'Bars' => [
    'entity' => 'Asprin\FB:Bar',
    'type' => self::TO_MANY,
    'conditions' => [['foo', '=', '$sys_id']],
    'primary' => true
],
'VisitorBar' => [
    'entity' => 'Asprin\FB:Bar',
    'type' => self::TO_ONE,
    'conditions' => [                
        ['user_id', '=', \XF::visitor()->user_id],
        ['foo', '=', '$sys_id']
    ],            
    'primary' => true
]

Now, if I'm logged in with an account whose user_id = 87 and do the following:

$foo->Bars --> I'm getting the correct result, i.e. 2 rows.
$foo->VisitorBar --> I'm getting wrong result, i.e. 1 row but upon dumping the result, the row with user_id = 45 is showing up. It should have been the one where user_id = 87.

Why isn't the user_id condition defined on the VisitorBar relation not taking effect and it seems to be pulling the first row always irrespective of who is logged in.
 
Top Bottom