activerecord - Rails: Get phone_number of persons in city -
i need phone numbers of people in 1 city, have db this:
class city < activerecord::base has_many :persons end ... class person < activerecord::base belongs_to :city has_many :phones end ... class phone < activerecord::base belongs_to :person end ...
so neet phones in 1 city this:
city.find(1).persons.phones
any help?
currently use this:
ids=city.find(1).persons.ids phones=phones.where(id: ids)
join nested has_many associations , apply clause this:
phone.joins(person: :city).where(cities: {id: 1})
Comments
Post a Comment