例: データベースのテーブルに次の 2 つのクラスがあります。
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
}
}
ここで、すべてのユーザーとそれに関連する投稿を 1 つの変数でクエリしたいと考えています。そんな感じ:
$user = Model::factory('User')->find_many();
// Find the posts associated with the user
$posts = $user->posts()->find_many();
$posts変数で結果を取得したい。