Making select() work in with() queries
->with(array('schools' => function($query) { $query->select('name'); } }
It would be nice if we could use select() with with() queries
I have a feeling this has been asked before. But even so I think it'd be cool to be able to limit queries even further when constraining them.
What happens if you try to do that now. What error do you get?
return Country::with(array('schools' => function($query)
{
$query->select('name');
}
))->get();
this will make all the countries have an empty schools array, even if they have schools
Try add "id" to the select and see if it works.
On May 12, 2013, at 3:26 PM, crissi [email protected] wrote:
return Country::with(array('schools' => function($query) { $query->select('name'); } ))->get(); this will make all the countries have an empty schools array, even if they have schools
— Reply to this email directly or view it on GitHub.
nope same result!
Hmm, I'll play with it later tonight.
On May 12, 2013, at 3:30 PM, crissi [email protected] wrote:
nope same result!
— Reply to this email directly or view it on GitHub.
NEVERMIND: I guess it only worked due to a join.
I got something like this working by using an array in the select() function like
...
$query->select(array('name'));
...
This works for me. Try updating your framework and verify the issue persists. I'm unable to recreate.
Updated composer. Still not working:(
Paste your models, entire queries, tables, etc
On May 18, 2013, at 9:54 AM, crissi [email protected] wrote:
Updated composer. Still not working:(
— Reply to this email directly or view it on GitHub.
I did some debugging: If this does not helps you out I will post everything!
I can see that this is firing this when I do not use a select:
'select * from schoolswhereschools.country_id in ('AD', 'AE', 'AF', 'AG')'
but as I use ->select('name'), it does not work:
'select namefromschoolswhereschools.country_id in ('AD', 'AE', 'AF', 'AG')'
It works if I do this: ->select('name', 'country_id');
because it is firing this:
'select name, country_idfromschoolswhereschools.country_id in ('AD', 'AE', 'AF', 'AG')'
The query have the country_id so it is possible for the framework to know what country the schools should be added to.
The same thing is happening on many to many relationships, There it is the pivot_something_id that is not being created when you use select()
Yes that is the danger of using select in those situations is you have to include the IDs.
On May 19, 2013, at 6:38 AM, crissi [email protected] wrote:
I did some debugging: If this does not helps you out I will post everything!
I can see that this is firing this when I do not use a select: 'select * from
schoolswhereschools.country_idin ('AD', 'AE', 'AF', 'AG')'but as I use ->select('name'), it does not work: 'select
namefromschoolswhereschools.country_idin ('AD', 'AE', 'AF', 'AG')'It works if I do this: ->select('name', 'country_id');
because it is firing this: 'select
name,country_idfromschoolswhereschools.country_idin ('AD', 'AE', 'AF', 'AG')'The query have the country_id so it is possible for the framework to know what country the schools should be added to.
The same thing is happening on many to many relationships, There it is the pivot_something_id that is not being created when you use select()
— Reply to this email directly or view it on GitHub.
I see, but wouldn't it be more convenient if the framework automatically took care of that.
It might be possible for us to do that, I'll have to look into it.
On May 19, 2013, at 9:09 AM, crissi [email protected] wrote:
I see, but wouldn't it be more convenient if the framework automatically took care of that.
— Reply to this email directly or view it on GitHub.
Cool!
Sendt fra min iPhone
Den 19/05/2013 kl. 16.34 skrev "Taylor Otwell" [email protected]:
It might be possible for us to do that, I'll have to look into it.
On May 19, 2013, at 9:09 AM, crissi [email protected] wrote:
I see, but wouldn't it be more convenient if the framework automatically took care of that.
— Reply to this email directly or view it on GitHub. — Reply to this email directly or view it on GitHub.
at the moment I am using the IDs to make it work and I am too looking forward to a better solution to this.
could this issue be opened?