示例:我对数据库中的表有以下两个类。
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变量中得到结果。