Last active
December 17, 2015 02:48
-
-
Save leocavalcante/5538194 to your computer and use it in GitHub Desktop.
Laravel 4 - Eager Load Constraints
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
Quota::with( | |
array( | |
'codes' => function($query) { | |
$query->where('number', '=', 11); | |
} | |
) | |
) | |
->where('label', '=', 'foo') | |
->whereRaw('quotas.count < quotas.limit') | |
->orderBy('count') | |
->orderBy('id', 'desc') | |
->get(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Select * | |
From quotas as q | |
Join codes as c | |
on (c.quotaId = q.id) | |
Where | |
q.label = 'foo' and | |
c.number = 11 and | |
q.count < q.limit | |
Order by | |
q.count asc, | |
q.id desc; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment