Skip to content

Instantly share code, notes, and snippets.

@adam8810
Last active December 21, 2015 05:49
Show Gist options
  • Save adam8810/6259898 to your computer and use it in GitHub Desktop.
Save adam8810/6259898 to your computer and use it in GitHub Desktop.
DB vs ORM
$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