4

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
twonegatives
  • 3,400
  • 19
  • 30
kannathasan
  • 565
  • 7
  • 21
  • 3
    err, can you use a real example? this is completely confusing – sevenseacat Jun 13 '14 at 11:38
  • possible duplicate of [A concise explanation of nil v. empty v. blank in Ruby on Rails](http://stackoverflow.com/questions/885414/a-concise-explanation-of-nil-v-empty-v-blank-in-ruby-on-rails) – kannathasan Oct 09 '14 at 14:22

1 Answers1

18

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
Peter Brown
  • 50,956
  • 18
  • 113
  • 146