【发布时间】:2011-08-12 15:14:18
【问题描述】:
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 或其他更精简的语法来定义自定义关联,就像命名范围一样优雅?
更新
我认为无论如何将这种细节放入关联中并不是一个好主意,因为关联应该始终/主要定义模型之间的基本关系。
【问题讨论】:
标签: ruby-on-rails ruby activerecord associations arel