Skip to content
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

[Request] Allow other query methods in Eloquent eager loading closure #55

Closed
johnnncodes opened this issue Jan 15, 2013 · 30 comments
Closed

Comments

@johnnncodes
Copy link

Currently, we can only use WHERE clauses in closures when eager loading. Like:

$users = User::with(array('posts' => function($query)
{
$query->where('title', 'like', '%first%');

}))->get();

Maybe allowing ORDERBY, LIMIT, OFFSET etc... will be a good idea? So we will have more control when eager loading something using Eloquent.

Something like:

$users = User::with(array('posts' => function($query)
{
$query->orderBy('created_at', 'desc');

}))->get();

@franzliedke
Copy link
Contributor

That's a huge +1 from me.

@djtarazona
Copy link
Contributor

+1

2 similar comments
@yuters
Copy link
Contributor

yuters commented Jan 15, 2013

👍

@billmn
Copy link
Contributor

billmn commented Jan 15, 2013

👍

@juukie
Copy link
Contributor

juukie commented Jan 15, 2013

Could be usefull sometimes! +1

@Meroje
Copy link

Meroje commented Jan 15, 2013

👍

@stevemo
Copy link

stevemo commented Jan 15, 2013

@AustinW
Copy link
Contributor

AustinW commented Jan 15, 2013

👍

3 similar comments
@ghost
Copy link

ghost commented Jan 16, 2013

+1

@asifrust
Copy link

+1

@jasonlewis
Copy link
Contributor

👍

@JonoB
Copy link
Contributor

JonoB commented Jan 16, 2013

+1

Btw, in the meantime, you can specify these arguments in the relationship if you wish.

@frankmayer
Copy link

👍

3 similar comments
@nicholasruunu
Copy link
Contributor

👍

@Dalamar
Copy link

Dalamar commented Jan 17, 2013

👍

@ghost
Copy link

ghost commented Jan 17, 2013

👍

@Globegitter
Copy link

+1

@ghost
Copy link

ghost commented Jan 18, 2013

@JonoB would you mind showing us an example of your workaround?

@tlgreg
Copy link

tlgreg commented Jan 18, 2013

@falzhobel

    public function posts()
    {
        return $this->hasMany('Post')->orderBy('created_at', 'desc');
    }

And a 👍

@JonoB
Copy link
Contributor

JonoB commented Jan 18, 2013

@falzhobel As @tlgreg demonstrated, you can have any clauses (orderBy, where, etc) in the relationship. Its not workable if you need dynamic clauses, but it works just fine if your clauses are always static.

@ghost
Copy link

ghost commented Jan 18, 2013

Thanks guys :)

@champiewebfolio
Copy link

+1

@taylorotwell
Copy link
Member

What makes you guys think this doesn't already work? It does and always has in Laravel 4.

@daylerees
Copy link
Contributor

💃

@jcldavid
Copy link

✌️

@tlgreg
Copy link

tlgreg commented Jan 18, 2013

Now that's just lol. Nice! 🍶

@yuters
Copy link
Contributor

yuters commented Jan 18, 2013

I +1'd this without taking the time to try it, but now I have and as @taylorotwell said, it works just like this in Laravel4.

We're just a bunch of gullible sheeps ! Haha

@ghost
Copy link

ghost commented Jan 18, 2013

Hahaha, indeed we are just a bunch sheeps. Thanks for the heads up @taylorotwell

@johnnncodes
Copy link
Author

Lol. This really made me laugh. :)) thank you so much @taylorotwell and sorry for opening this feature request :))

@asifrust
Copy link

LoL :D Another Sheep here. thanx @taylorotwell

On Sat, Jan 19, 2013 at 5:02 AM, John Kevin M. Basco <
[email protected]> wrote:

Lol. This really made me laugh. :)) thank you so much @taylorotwellhttps://github.com/taylorotwelland sorry for opening this feature request :))


Reply to this email directly or view it on GitHubhttps://github.com//issues/55#issuecomment-12444967.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests