gpt4 book ai didi

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

转载 作者:搜寻专家 更新时间:2023-10-31 20:38:42 24 4
gpt4 key购买 nike

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

            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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com