Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Select on a related table
I have a problem with ORM requests. I have two tables : Patients and Users, related with a many to many relationship.
I'd like to get all Patients of a User, but I don't want to fetch all the fields of the User's table.
So, I do :
But it gives me all the fields of the related user, but I don't want it (it contains the username, the hashed password, etc), I want to select specific fields.
I saw this post and it wasn't posible in January 2012. I want to know if it's possible today.
The workaround is to make a model (Patientsusers or so) for the through table too, and define that in both models as a separate relation. You can then do
users_id', '=', $user_id)->get();
That will join the through table, but not the users table.
Alternatively, run the query the other way around:
if ($user = Model_Users::query()->related('patients')->where('id', '=',
$patients = $user->patients;
I don't want to change relationships so I will apply the second solution, I didn't think about it.
Add a Comment
It looks like you're new here. If you want to get involved, click one of these buttons!
Apply for Membership
↳ Job Board
↳ Installation & Setup
↳ Tips and Tutorials
↳ Code share
In this Discussion