Last active
December 21, 2015 05:49
-
-
Save adam8810/6259898 to your computer and use it in GitHub Desktop.
DB vs ORM
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
$query = DB::select(DB::expr('person.homeid, home.addressid, person.personid, person.firstName, person.middleName, person.lastName, person.gender, person.maritalStatus, person.birth')) | |
->from(DB::expr('home, person')) | |
->where(DB::expr('home.homeid'), DB::expr('person.homeid')) | |
->and_where(DB::expr('person.homeid'), $homeid); | |
$people = Person::query() | |
->related('homes') | |
->get(); | |
// list people's addresses | |
foreach ($people as $p) { | |
echo 'home for this person is '. $p->home->address1. ' '. $p->home->address2 [...]; | |
} | |
// list only homes for one person | |
foreach ($people->home as $h) { | |
echo $h->address1; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment