ruby on rails - Validate object based on the owner its parent -
i have has_many through association setup between artist , album models. add album has_many tracks. tracks have has_many through association between artists (i.e. featured artist ) feature model serves join table. i want prevent album artist(s) being featured artist on track. instance: album = album.find_by(name: "justified") track = album.track.first artist = artist.find_by(name: "justin timberlake") track.featured_artists << artist # ^^ should raise error since justin timberlake album's artist model setup class album < activerecord::base has_many :album_artists has_many :artists, through: :album_artists end class track < activerecord::base belongs_to :album has_many :features has_many :featured_artists, through: :features, class_name: "artist", foreign_key: "artist_id" end class albumartist < activerecord::base belongs_to :album belongs_to :artist validates_uniqueness_of :artist_id, sco...