php - 在巴黎需要帮助 php 查询

标签 php idiorm

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

            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);
            }

关于php - 在巴黎需要帮助 php 查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28916396/

相关文章:

php - 使用 CodeIgniter 将图像上传到我的数据库

php - 模块 install.mysql.utf8.sql 中的 joomla 2.5 不起作用

php - idiorm/paris - 将 null 写入数据库

php - 成语 find_many() 只返回一个对象

php - PDO 插入不工作

php - 在没有 <br> 标签的情况下重新填充 textarea 中保存的 nl2br 内容?

php - 捕获成语和巴黎 orm 中的错误?

php - 习语查询数

php - 非主键自增字段

javascript - PHP 注册从返回到错误的 URL 而不是索引,数据库错误?