我想在我的ActiveRecord模型中输入我自己的has_many
关系的条件。 我要我的条件为覆盖的默认条件。如何覆盖rails中关系的默认has_many条件?
Class User < ActiveRecord::Base
has_many :notifs, :conditions =>
proc { "(notifs.user_id = #{self.id} OR notifs.user_id = 0)" }
并生成:
NOTIF负荷(在0.2ms)SELECT
notifs
* FROMnotifs
WHEREnotifs
。user_id
= 1 AND((notifs.user_id = 1或notifs.user_id = 0))
我不希望活动记录的默认状态(第一WHERE notifs.user_id = 1
外括号)。我只想要我自己的。我如何指定?
'finder_sql'从[4.1]删除(https://github.com/rails/rails/blob/4-1-stable/activerecord/CHANGELOG.md)。 – droptheplot