Join multiple tables with active records

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:

Leave a Comment