XF 2.2 Joins only support TO_ONE relationships

Robert9

Well-known member
To show watched resources we use:

Code:
        $finder
            //->with(['full', 'fullCategory'])
            ->with('Watch|' . $userId, true)
            ->where('resource_state', 'visible')
            ->setDefaultOrder('last_update', 'DESC');

This results in

Code:
SELECT `xf_rm_resource`.*, `xf_rm_resource_watch_Watch_1`.*
FROM `xf_rm_resource`
INNER JOIN `xf_rm_resource_watch` AS `xf_rm_resource_watch_Watch_1` ON (`xf_rm_resource_watch_Watch_1`.`resource_id` = `xf_rm_resource`.`resource_id` AND `xf_rm_resource_watch_Watch_1`.`user_id` = '1')
WHERE (`xf_rm_resource`.`resource_state` = 'visible')
ORDER BY `xf_rm_resource`.`last_update` DESC


Now I want to sort by User.last_activity

Code:
//->with(['full', 'fullCategory'])
->with('Watch|' . $userId, true)
->where('resource_state', 'visible')
->setDefaultOrder('User.last_activity', 'DESC');

No problem, it results in

Code:
SELECT `xf_rm_resource`.*, `xf_rm_resource_watch_Watch_1`.*
FROM `xf_rm_resource`
INNER JOIN `xf_rm_resource_watch` AS `xf_rm_resource_watch_Watch_1` ON (`xf_rm_resource_watch_Watch_1`.`resource_id` = `xf_rm_resource`.`resource_id` AND `xf_rm_resource_watch_Watch_1`.`user_id` = '1')
LEFT JOIN `xf_user` AS `xf_user_User_2` ON (`xf_user_User_2`.`user_id` = `xf_rm_resource`.`user_id`)
WHERE (`xf_rm_resource`.`resource_state` = 'visible')
ORDER BY `xf_user_User_2`.`last_activity` DESC

But now I aim to sort with xf_rm_resource_watch

Code:
//->with(['full', 'fullCategory'])
            ->with('Watch|' . $userId, true)
            ->where('resource_state', 'visible')
            ->setDefaultOrder('Watch.user_id', 'DESC');

and get

Joins only support TO_ONE relationships currently in src/XF/Mvc/Entity/Finder.php at line 789

And how can I sort now by Watch / xf_rm_resource_watch?

This works.

Code:
SELECT `xf_rm_resource`.*, `xf_rm_resource_watch_Watch_1`.* FROM `xf_rm_resource` INNER JOIN `xf_rm_resource_watch` AS `xf_rm_resource_watch_Watch_1` ON (`xf_rm_resource_watch_Watch_1`.`resource_id` = `xf_rm_resource`.`resource_id` AND `xf_rm_resource_watch_Watch_1`.`user_id` = '1') LEFT JOIN `xf_user` AS `xf_user_User_2` ON (`xf_user_User_2`.`user_id` = `xf_rm_resource`.`user_id`) WHERE (`xf_rm_resource`.`resource_state` = 'visible') ORDER BY `xf_rm_resource_watch_Watch_1`.`user_id` DESC

How can I do that with the finder, please?
 
Top Bottom