在巴黎需要帮助 php 查询


Need help in Paris php quering

示例:我有以下两个用于数据库中表的类。

            class Post extends Model {}
            class User extends Model {
               public function posts() {
                   return $this->has_many('Post'); // Note we use the model name literally - not a    pluralised version
               }
            }

现在我想在一个变量中查询所有用户及其相关帖子。像这样:

            $user = Model::factory('User')->find_many();
            // Find the posts associated with the user
            $posts = $user->posts()->find_many();

我想在变量$posts得到结果。

我已经自己解决了这个问题

            $user = Model::factory('User')->find_many();
            // Find the posts associated with the user
            //$posts = $user->posts()->find_many();

我循环遍历$user并将每个用户 ID 传递给 $user->posts()->find_one();

sudo 代码在这里:

            foreach($user as $usr)
            {
               $posts = $user->posts()->find_one($usr->Id);
            }