Suppose I have several different models and I'm building up a complex relation by passing them to other classes like:
class UserDefinedParameter
def apply(base_relation)
base_relation.where(:abc => self.value)
#I want to see if base_relation was a ModelA here
end
end
class UserDefinedSort
def apply(base_relation)
base_relation.sort("#{self.col} DESC")
end
end
[ModelA, ModelB].each do |m|
result = m.where(:user => current_user)
UserDefinedParameter.all {|udp| result = udp.apply(result)}
UserDefinedSort.all {|uds| result = uds.apply(result)}
end
What if I need to know whether I have ModelA
or ModelB
inside one of the apply
methods? How could I determine this?
I can't do base_relation.first.class
(like suggested here because the query isn't fully formed and ready to go to the database yet.