model/books/user.php
public static function get_books_for_user($username) {
$result = Model_Book::query()->related('user')->where('user.username','=',$username)->get();
return $result;
}
UnexpectedValueException [ Error ]:
Relation "user" was not found in the model.
protected static $_has_one = [];
protected static $_has_many = [];
protected static $_belongs_to = [];
protected static $_many_many = [];
protected static $_many_many = array(
'users' => array(
'key_from' => 'id',
'key_through_from' => 'book_id',
'table_through' => 'books_users',
'key_through_to' => 'user_id',
'model_to' => 'Model_User',
'key_to' => 'id',
'cascade_save' => true,
'cascade_delete' => false,
)
);
protected static $_many_many = array(
'books' => array(
'key_from' => 'id',
'key_through_from' => 'book_id',
'table_through' => 'books_users',
'key_through_to' => 'user_id',
'model_to' => 'Model_Book',
'key_to' => 'id',
'cascade_save' => true,
'cascade_delete' => false,
)
);
$result = Model_Book::query()->related('users')->where('users.username','=',$username)->get();
It looks like you're new here. If you want to get involved, click one of these buttons!