P
P
Pavel2013-02-25 09:25:33
MySQL
Pavel, 2013-02-25 09:25:33

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();

How to select all included articles of a certain type is also clear:
$art = ORM::factory(Art)->where(‘enable’, ‘=’, 1)->and_where(‘type, ‘=’, ‘news’)->find_all();

But how to select all included articles, of a certain type from a certain category (all links are registered), is not at all clear. Well, the question is, is it possible to do this with one request, and if so, how?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
H
hellgirl, 2013-02-25
@parsek

$art = ORM::factory(Art)
->with('artcart')
->where('artcart.id_cat', '=', 1)
->where('enable', '=', 1)-> and_where('type, '=', 'news')->find_all();

E
Evgeny Leshchenko, 2013-02-25
@xsen

$category->arts->where()->find_all()

D
Dmitry Balobanov, 2013-02-25
@pchelkin

join

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question