postgresql - nested joins statement in rails app -
in rails appi have 4 models( a, b, c, d, e , f)
- a belongs b
 - b has many cs
 - c belongs d
 - d belongs e , f
 
i trying build query follows
scope = a.joins(:b, { b: [:cs, {cs: [:d, {d: [:e,:f] } ] } ] })   but not working. error message schema cs (plural of c) not exist.
i using postgresql.
well, seems you're missing b reference (b_id) in c model. c needs know b belongs. after that, can simplify query this:
a.joins(b: {cs: {d: [:e, :f]}})      
Comments
Post a Comment