|
|
|
@ -22,34 +22,57 @@ class Person
|
|
|
|
people.*,
|
|
|
|
people.*,
|
|
|
|
locations.street,
|
|
|
|
locations.street,
|
|
|
|
locations.city,
|
|
|
|
locations.city,
|
|
|
|
locations.state
|
|
|
|
locations.state,
|
|
|
|
|
|
|
|
companies.id AS company_id,
|
|
|
|
|
|
|
|
companies.name AS company,
|
|
|
|
|
|
|
|
companies.industry
|
|
|
|
FROM people
|
|
|
|
FROM people
|
|
|
|
LEFT JOIN locations
|
|
|
|
LEFT JOIN locations
|
|
|
|
ON people.home_id = locations.id
|
|
|
|
ON people.home_id = locations.id
|
|
|
|
|
|
|
|
LEFT JOIN jobs
|
|
|
|
|
|
|
|
ON people.id = jobs.person_id
|
|
|
|
|
|
|
|
LEFT JOIN companies
|
|
|
|
|
|
|
|
ON jobs.company_id = companies.id
|
|
|
|
SQL
|
|
|
|
SQL
|
|
|
|
)
|
|
|
|
)
|
|
|
|
return results.map do |result|
|
|
|
|
people = []
|
|
|
|
if result["home_id"]
|
|
|
|
last_person_id = nil
|
|
|
|
home = Location.new(
|
|
|
|
results.each do |result|
|
|
|
|
|
|
|
|
if result["id"] != last_person_id
|
|
|
|
|
|
|
|
last_person_id = result["id"]
|
|
|
|
|
|
|
|
if result["home_id"]
|
|
|
|
|
|
|
|
home = Location.new(
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
"id" => result["home_id"],
|
|
|
|
|
|
|
|
"street" => result["street"],
|
|
|
|
|
|
|
|
"city" => result["city"],
|
|
|
|
|
|
|
|
"state" => result["state"],
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
home = nil
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
new_person = Person.new(
|
|
|
|
{
|
|
|
|
{
|
|
|
|
"id" => result["home_id"],
|
|
|
|
"id" => result["id"],
|
|
|
|
"street" => result["street"],
|
|
|
|
"name" => result["name"],
|
|
|
|
"city" => result["city"],
|
|
|
|
"age" => result["age"],
|
|
|
|
"state" => result["state"],
|
|
|
|
"home" => home,
|
|
|
|
|
|
|
|
"employers" => []
|
|
|
|
}
|
|
|
|
}
|
|
|
|
)
|
|
|
|
)
|
|
|
|
else
|
|
|
|
people.push(new_person)
|
|
|
|
home = nil
|
|
|
|
end
|
|
|
|
|
|
|
|
if result["company_id"]
|
|
|
|
|
|
|
|
employer = Company.new({
|
|
|
|
|
|
|
|
"id" => result["company_id"],
|
|
|
|
|
|
|
|
"name" => result["company"],
|
|
|
|
|
|
|
|
"industry" => result["industry"]
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
people.last.employers.push(employer)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
Person.new(
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
"id" => result["id"],
|
|
|
|
|
|
|
|
"name" => result["name"],
|
|
|
|
|
|
|
|
"age" => result["age"],
|
|
|
|
|
|
|
|
"home" => home,
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
return people
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
def self.find(id)
|
|
|
|
def self.find(id)
|
|
|
|
|