Answer the question
In order to leave comments, you need to log in
How to select in kohana ORM when using _has_many relationship?
Task: to organize the search by articles.
Given: for simplicity, I will reduce the tables to a minimum (in fact, there are many times more sampling parameters and there are several connecting tables):
Table with articles art : id, enable, type, title
Table with categories cat : id, title Linking
table artсat : id_art, id_cat
Like select all included articles, clear:
$art = ORM::factory(Art)->where(‘enable’, ‘=’, 1)->find_all();
$art = ORM::factory(Art)->where(‘enable’, ‘=’, 1)->and_where(‘type, ‘=’, ‘news’)->find_all();
Answer the question
In order to leave comments, you need to log in
$art = ORM::factory(Art)
->with('artcart')
->where('artcart.id_cat', '=', 1)
->where('enable', '=', 1)-> and_where('type, '=', 'news')->find_all();
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question