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

Popular posts from this blog

ruby on rails - RuntimeError: Circular dependency detected while autoloading constant - ActiveAdmin.register Role -

c++ - OpenMP unpredictable overhead -

javascript - Wordpress slider, not displayed 100% width -