From 87e70da120976b07e11d1f4ac4e7c101711f67db Mon Sep 17 00:00:00 2001 From: Matt Huntington Date: Sat, 23 Sep 2017 11:03:04 -0400 Subject: [PATCH] adding location to person model --- database/sql/people/find.sql | 5 +++++ models/person.php | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/database/sql/people/find.sql b/database/sql/people/find.sql index 3863aec..5e1aa99 100644 --- a/database/sql/people/find.sql +++ b/database/sql/people/find.sql @@ -2,11 +2,16 @@ SELECT people.id AS person_id, people.name AS person_name, age, + locations.id as location_id, + locations.street, + locations.city, + locations.state, jobs.id AS job_id, job_type, companies.id AS company_id, companies.name AS company_name FROM people +LEFT JOIN locations ON people.location_id = locations.id LEFT JOIN jobs ON people.id = jobs.person_id LEFT JOIN companies ON jobs.company_id = companies.id ORDER BY people.id ASC; diff --git a/models/person.php b/models/person.php index 2ec41f8..45a15f8 100644 --- a/models/person.php +++ b/models/person.php @@ -2,6 +2,7 @@ include_once __DIR__ . '/../database/db.php'; include_once __DIR__ . '/job.php'; include_once __DIR__ . '/company.php'; +include_once __DIR__ . '/location.php'; class Person { public $id; @@ -31,6 +32,10 @@ class People { $new_job->company = new Company(intval($data->company_id), $data->company_name); $current_person->jobs[] = $new_job; } + if($data->location_id){ + $new_location = new Location(intval($data->location_id), $data->street, $data->city, $data->state); + $current_person->location = $new_location; + } } return $people;