-
Notifications
You must be signed in to change notification settings - Fork 478
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Custom "with()" method that has two joins, how to? #220
Comments
Are you sure it is line 473? Because looking at MY_Model, I don't see anything written on that line... |
@paulcanning check MY_Model version . i think it`s happends on empty results (closed issue) |
@avenirer Definitely that line number! Does anyone know if its possible to write a custom method, e.g. So I could do |
@paulcanning Sure, its return model object and you can call get() or get_all() or any other MY_Model method |
@michail1982 care to provide an example? :) |
$this->model->with('owner')->my_custom_query_method()->get_many_by(('score' => 1)); |
Sorry, I meant an example of how I write the custom method to return the object so it can be used with |
return $this; |
I am struggling to write a custom "with()" method that involves two joins.
I'll try to breakdown my tables:
Users - generic table, users can be joined to other tables via lookup tables.
Resellers - entity that describes a reseller, has an owner_id which is a foreign key to users.id
Agents - lookup table to connect a (different) user to a reseller, as an agent (sales person). Can be multiple per reseller.
So, typically, looking up a reseller, I can get the owner (users) details by using the $belongs_to relationship and using "with('users')" in my call, before get_all() eg $this->resellers->with('users')->get_all()
This works great!
Now, the tricky part.
I want to get the above, but with the agent(s) details. eg $this->reseller->with('users')->with_agents()->get_all()
I tried the following:
But I get an error:
Sooo, how can I write a custom "with()" method, that has multiple joins, and where it is fetching one or more results? (not just one result like the user join)
The text was updated successfully, but these errors were encountered: