I want to know the banner name situated in a great grandchildren tab. Here\'s how my data base is:
Inscription (where I need to start from): Item1_id
Item1:
You can do the following:
Inscription.includes(item1: { item2: :banner })
The relations names item1, item2 and banner need to match the names given to each relation.
If you want to set a where statement on this query, you can do:
scope = Inscription.includes(item1: { item2: :banner })
scope = scope.where(banner: { name: "MOTD: Hello World!" })
scope = scope.where(item2: { is_favorite: true })
Similar questions: