activerecord - how to override HABTM table in rails -
i having using rails 3 , have habtm(has_and_belongs_to_many) between users <-> emails user have roles defined users subs, pubs have model references mapping.
i want send emails trash/spam/etc 1 single user. how can achieve, if delete 1 email it'll removed every user having habtm. want show email trashed/spam etc. have wild thought of overriding habtm table setting spam/trash flags/columns in table, when user marks spam/trash email. he'll able work there way/convention that.
i reckon can away setting associations shown below. note dependent: :destroy. when delete user activerecord cause call dependent: :destroy on model , delete associated model it.
class user < activerecord::base has_many :emails, through: :user_emails has_many :emails, dependent: destroy end class useremail < activerecord::base belongs_to :user belongs_to :email end class email < activerecord::base has_many :users, :through: :user_emails has_many :user_emails, :dependent: :destroy end you can have under polymorphic associations. helps
update querying has_many association
@useremail = useremail.find(:all, :joins => :user, :email, :conditions => ["email.email_trashed = ? ", true] ) not 100% work reckon along them lines.
Comments
Post a Comment