Tiamon
Tiamon

Reputation: 237

nested joins statement in rails app

In my rails appI have four models( say A, B, C, D, E and F)

I am trying to build query as follows

scope = A.joins(:b, { b: [:cs, {cs: [:d, {d: [:e,:f] } ] } ] })

But it is not working. The error message is schema cs (plural of c) does not exist.

I am using Postgresql.

Upvotes: 0

Views: 59

Answers (1)

Jiří Pospíšil
Jiří Pospíšil

Reputation: 14402

Well, it seems like you're missing a B reference (b_id) in the C model. C needs to know to which B it belongs. After that, you can simplify the query to this:

A.joins(b: {cs: {d: [:e, :f]}})

Upvotes: 1

Related Questions