diff --git a/database/sql/locations/find.sql b/database/sql/locations/find.sql index bdba063..38d1c9a 100644 --- a/database/sql/locations/find.sql +++ b/database/sql/locations/find.sql @@ -1 +1,11 @@ -SELECT * FROM locations +SELECT + locations.id AS location_id, + street, + city, + state, + people.id AS person_id, + name, + age +FROM locations +LEFT JOIN people ON locations.id = people.location_id +ORDER BY locations.id; diff --git a/models/location.php b/models/location.php index 52be2b8..03fbd74 100644 --- a/models/location.php +++ b/models/location.php @@ -1,5 +1,6 @@ id), $data->street, $data->city, $data->state); + if($current_location === null || $current_location->id !== intval($data->location_id)){ + $current_location = new Location(intval($data->location_id), $data->street, $data->city, $data->state); + $current_location->residents = []; + $locations[] = $current_location; + } + if($data->person_id){ + $new_person = new Person(intval($data->person_id), $data->name, intval($data->age)); + $current_location->residents[] = $new_person; + } + } return $locations;