Non-Cohan Tables 3.1 ORM

How do I make this work?

$stuff = ORM::factory('mytable') ->with('user') ->with('other_stuff') ->find_all(); 

I have all my relationships and everything works when I make other requests. However, in the above query, it does not join the user table with mytable . I think it could be because there can be many users for one mytable.

There is a method in the link called join() , which, I think, I may need to use here, but it does not provide any information about this, and the material that I searched from above does not work here.

When I try to use join instead of with , it tries to join the table, but it does not contain any join information, just gives an empty () .

I know that my relationship with ORM DB is set up correctly, so I'm a bit puzzled.

+4
source share
2 answers

Kohana has decent documentation without looking at the right place ... well, your problem.

ORM::with() used to load one-to-one relationships (applies to one and has one), although you have all the Database_Query_Builder methods for use with ORM at your disposal:

 $stuff = ORM::factory('mytable') ->join('users','LEFT') ->on('users.mytable_id','=','mytables.id') ->find_all(); 
+5
source
 SELECT * from table1 LEFT JOIN table2 ON table1.id = table2.id AND table2.flag = 'Y' AND table2.siteid = '12' WHERE table1.siteid = '12' 

How is the above query written in the Kohana ORM format? Is the following indicated correctly?

 $stuff = ORM::factory('table1') ->join('table2','LEFT') ->on('table1.id','=','table2.id') ->on('table2.flag','=','Y') ->on('table2.siteid', '=', '12') ->where('table1.id', '=', '12') ->find_all(); 
+1
source

All Articles