Joins more than two tables with activerecord

Some time ago, I asked (joins across several tables using ActiveRecord with named scopes) Comes into several tables using ActiveRecord with named scopes

Now I need to create a named scope that includes a join of more than two tables, for example:

named_scope :baz_category, lambda {|c| {:joins=>([:foo,:bar,:baz]):conditions=>['baz_cat=',c]}}

Where Foo has one bar and one bar, there is one Baz.

I would like the solution to work on 4th or 5th, etc. tables.

Thank you very much for helping me with this.

+3
source share
2 answers

named_scope :baz_category, lambda { |c| :joins => {:foo => { :bar => :baz } }

The nest is as deep as you want.

+3
source

? .

+1

Source: https://habr.com/ru/post/1716066/


All Articles