model Post
# ActiveRecord associations have tons of options that let
# you do just about anything like:
has_many :comments
has_many :spam_comments, :conditions => ['spammy = ?', true]
# In Rails 3, named scopes are ultra-elegant, and let you do things like:
scope :with_comments, joins(:comments)
end
有没有什么方法可以使用AREL或其他更精简的语法来将自定义关联定义为与命名作用域一样优雅?有没有办法使用AREL进行自定义关联?
更新
我已经决定了这不是一个好主意,把那种细节的为关联关系,无论如何,因为协会应始终/大都定义模型之间的基本关系。
是的我见过这个......我认为把它称为“关联”并不好,因为它没有定义两个模型之间的关系。 – 2011-04-26 15:34:30
性能明智,这是否具有与通过关联限制查询相同的效果? (初学者在这里) – noli 2011-07-15 03:25:01