In a situation i need to join the 4 scopes among the 4 scopes 3 are written in model(A) and one in another model(B) how to join those scopes?
those two models have HABTM relationship
Model A
scope 1
scope 2
scope 3
total_scope= scope1.scope2.scope3.scope4
end
Model B
scope 4
end
Your question isn't very well worded, but I think what you're asking is related to Active Record's merge feature:
class ModelA
scope :total_scope, -> { scope1.scope2.scope3.joins(:modelb).merge(ModelB.scope4)
end
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With