samedi 5 décembre 2015

How can I merge two active record relation with OR condition in rails 3 and return result also an active relation not array?

I have two associations like surgical_diseases and eye_disease.I want to get the Ored result of the two active relation.But the below code gave me an array.

 has_many :surgical_diseases
 has_many :eye_disease

 scope :all_disease ->(name) { joins(:surgical_diseases).where('surgical_diseases.name IN (?)') | joins(:eye_disease).where('eye_disease.name IN (?)') }

I have seen active-record-union gem but that would only work with active-record 4.I am currently using rails 3.2 so not able to use that.

I also saw that this functionality will come with rails5 with dhh's commit.But not sure how will I fix this with rail3 now.

I tried my best to make understanding of my question.Please let me know if anything else information is require. Thanks in advance!

Aucun commentaire:

Enregistrer un commentaire