Rails - ActiveRecord includes multiple levels

See below:

class Continent < ActiveRecord::Base
    has_many :countrys

class Country < ActiveRecord::Base
    belongs_to :continent
    has_many :addresses

class Address < ActiveRecord::Base
    belongs_to :person
    belongs_to :street

class Person < ActiveRecord::Base
    has_many :addresses

      

How can I start with Person.includes()

and include associations all the way to continent when requesting db.

I was able to turn up the country through .includes(addresses: :country)

but didn't seem to get the last level.

+3


source to share


1 answer


You can add 1 more hash level:



... includes (addresses: {country :: continent})

+6


source







All Articles