"用户跟随"与PropelORM - 三种关系

Kyl*_*lan 17 php mysql orm propel

有人能指出我正确的方向做一个"用户跟随"的事情.我有3个表:users,user_follows和posts.

如果我给用户对象加水,我可以得到他们遵循的用户ID数组......并且帖子对象知道哪个用户发布了它......但是很难为给定用户所关注的用户获取帖子.

目前有这个,它返回每个人的帖子.

    $posts = PostsQuery::create()
        ->orderByDate('desc')
        ->limit('12')
        ->find();
    return $posts;
Run Code Online (Sandbox Code Playgroud)

需要做filterByXXX()......

den*_*ned 1

Propel ORM 不支持同一个表的实体之间的多对多关系。但您可以使用EqualNestBehavior来使其正常工作。

这样你的代码可能看起来像这样:

$user = UsersQuery::create()->findPk($userId);

$follows = $user->getFollows();

$posts = PostsQuery::create()
        ->filterByUser($follows)
        ->orderByDate('desc')
        ->limit('12')
        ->find();
Run Code Online (Sandbox Code Playgroud)

这是架构的相关部分:

$user = UsersQuery::create()->findPk($userId);

$follows = $user->getFollows();

$posts = PostsQuery::create()
        ->filterByUser($follows)
        ->orderByDate('desc')
        ->limit('12')
        ->find();
Run Code Online (Sandbox Code Playgroud)