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