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
subquery in select orm
itcan
April 2013
Hi guys,
can someone please tell me how to use a subquery in a select() statement in ORM/Query builder?
In the where() function I can make it work... But in select it doesn't work...
$subquery = \Model_User_Log::query()->select(\DB::expr('COUNT(*) AS counter'))->where('user_log.user_id','user.id');
$query = \Model_User::query()->select($subquery->get_query());
Harro
April 2013
get_query() returns the SQL as a string, so that will never work. You should be able to just pass the query itself:
$query = \Model_User::query()->select($subquery);
itcan
April 2013
Nope that also doesn't seem to work...
Harro
April 2013
Looked at the code, and indeed, you can't do that.
You have to take into account that an ORM is not a query builder. It's make to allow object oriented access to your database.
What exactly are you trying to do here? Count the number of log-entries per user? This is very easily done with a standard DB query.
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
April 2013
itcan
April 2013