简短的回答,这取决于。对于长答案,请继续阅读...
条件关联允许我们自定义ActiveRecord
用于获取关联的查询。当您确定此条件是永久性的并且您永远不需要访问不符合条件的数据(至少不在此模型中)时使用,因为条件关联适用于每个查询以ActiveRecord
执行来自该特定的关联模型。
Scope It is basically, a class method for retrieving and querying objects. so what you are actually doing is defining the following method in your model.
class Client < ActiveRecord::Base
self.approved
where(:approved => true)
end
end
so scope
is generally use to define short names for one or more regularly used query customization. But important difference is that scope
is not auto-applied unless you use default_scope
but conditional associations are auto-applied.
In your case, you want to show unapproved accounts in this model? If not, then use conditional association. Else use scope