Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ## 2 queries, union in ruby :(
- # this works, but it requires making the query and can't build a relation.
- class Baz < ActiveRecord::Base
- def foos
- baras_foos = Foo.joins(:baras).where(:baras => {:baz_id => id})
- barbs_foos = Foo.joins(:barbs).where(:barbs => {:baz_id => id})
- bar_a_foos | bar_bs_foos
- end
- end
- ## attempt at the relation approach :|
- # this sort of works, but there are many duplicate records.
- class Baz < ActiveRecord::Base
- def foos
- Foo.joins(:baras, :barbs).where(Bara.arel_table[:baz_id].eq(id).or(Barb.arel_table[:baz_id].eq(id)))
- end
- end
- ## the proper relation approach :)
- ?
Add Comment
Please, Sign In to add comment