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.
General
DB join on with a value problem
itcan
September 2014
Hi I want to create a query like this:
$user_id = 5;
$query = \DB::select('companies.*', \DB::expr('IF(test.user_id,"YES","NO") AS connected'))
->from('companies')
->join('test', 'LEFT')
->on('test.company_id', '=', 'companies.id')
->on('test.user_id', '=', $user_id)
->order_by('connected', 'DESC')
->order_by('companies.count_blogs', 'DESC')
->as_object()
->execute();
But this gives a problem with this line:
->on('test.user_id', '=', $user_id)
I want the join to look like this: LEFT JOIN test ON (
test.company_id=companies.id AND test.user_id=5
)
it seems it cannot bind a variable to a join, only columns...
itcan
September 2014
created an issue on github for it:
https://github.com/fuel/core/issues/1768
itcan
September 2014
it seems this works:
->on('test.user_id', '=', \DB::expr($user_id))
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
itcan
September 2014