adding location to person model

master
Matt Huntington 8 years ago
parent c7b4db9332
commit 87e70da120

@ -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;

@ -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;

Loading…
Cancel
Save