Last active
May 14, 2016 23:39
-
-
Save iwankgb/dc54e1e2b20cc566ad95 to your computer and use it in GitHub Desktop.
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 | |
/* | |
* Wykorzystując Illuminate\Database\Query\Builder wyciągam dane z bazy | |
*/ | |
$result = \DB::table('a')->join('b', 'a.id', '=', 'b.a_id')->where('b.id', 1)->get(); | |
/* | |
* Po tej operacji będę miał w garści tablicę instancji stdClass (albowiem ten akurat builder nie wie nic o modelu) | |
* w związku z tym hydruję model i iteruję po wyniku | |
*/ | |
$models = A::hydrate($results); | |
foreach ($models as $model) { | |
/* | |
* Mam też na stanie tabelę c - pozostającą w relacji n:1 z a | |
* W związku z tym poniższy wiersz spowoduje wysłanie do bazy zapytania dla każdej z iteracji pętli | |
*/ | |
$model->a(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Nie uruchamiałem tego kodu, mogą w nim być jakieś głupie błędy. Koncepcja jest imho dość jasna.