I would like to enter my own condition for a has_many
relationship in my ActiveRecord model.
I want my condition to override the default condition.
Class User < ActiveRecord::Base
has_many :notifs, :conditions =>
proc { "(notifs.user_id = #{self.id} OR notifs.user_id = 0)" }
And it generates:
Notif Load (0.2ms) SELECT
notifs
.* FROMnotifs
WHEREnotifs
.user_id
= 1 AND ((notifs.user_id = 1 OR notifs.user_id = 0))
I don't want the default condition of active record (the first WHERE notifs.user_id = 1
outside parens). I want only my own. How do I specify that ?