I’ve got a situation where I want a has_many :through association to
somewhat like a normal has_many when << is called on the association.
would like it to return false instead of throwing an exception.
With some inspiration from http://blog.hasmanythrough.com I’ve come up
class Container < AR:B
has_many :items, :through => :container_items do
def <<( item )
rescue ActiveRecord::RecordInvalid => e
@owner.errors.add( :item, e)
Is there anything that stands out as a stark issue with doing this? I
like to call owner in some other way but I have not found how to get at
@owner with a method.
The join model has only timestamps in addition to the two f’keys
Any comments, insights, crits etc are welcome.
I’ve extracted this into a plugin if anyone would like to try it. I
make any guarantees though.