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

Popular posts from this blog

css - SVG using textPath a symbol not rendering in Firefox -

Java 8 + Maven Javadoc plugin: Error fetching URL -

order - Notification for user in user account opencart -