Love Fuel?
Donate
About
Forums
Discussions
Login
FuelPHP Forums
Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Orm
How to join tables in Orm relation
miss_chan
July 2015
How to join hotel and master tables to get "hotel name" which is searching by hotel name in text box.
Hotel name column is only include in hotel table.
Tables:
hotel(hotel_code,hotel_name)
master_account(master_code,hotel_code)
my code is,(...fuel\app\modules\account\classes\controller\account.php)
$data['master_accounts'] = \Model_Master_Account::find('all', array(
'related' => array(
'hotel' => array(
'join_type' => 'left',
'join_on' => array(
array('hotel_code', '=', \DB::select('hotel_code')->from(\Model_Hotel::table())->where('hotel_name', 'like','%'.$hotel.'%')),
),
),
),
'order_by' => array('master_code' => 'desc'),
)
);
Harro
July 2015
Accepted Answer
ORM queries are left joins by default.
I personally never use find() and array notation, as it becomes messy and difficult to read very quickly, as you can see.
;-)
This should work fine:
$data['master_accounts'] =
\Model_Master_Account::query()
->related('hotel')
->
where('hotel.hotel_name', 'like','%'.$hotel.'%')
->order_by('master_code', 'desc')
->get();
miss_chan
July 2015
Yeah,got it.
Thank you,Mr.Harro Verton
:-)
Add a Comment
Howdy, Stranger!
It looks like you're new here. If you want to get involved, click one of these buttons!
Sign In
Apply for Membership
Categories
All Discussions
5,088
General
↳ General
3,364
↳ Job Board
13
↳ Installation & Setup
214
Packages
↳ Oil
213
↳ Orm
700
↳ Auth
260
Development
↳ Tips and Tutorials
126
↳ Code share
145
↳ Applications
52
In this Discussion
Harro
July 2015
miss_chan
July 2015