You could put a unique constrain across the ids
in the DB, then add the association in a begin/
rescue block, thereby squashing the error if it''s
a duplicate.
--
-- Tom Mornini
On Jun 20, 2006, at 12:35 PM, s.ross wrote:
>
> I have a habtm that looks like:
>
> report
> has_and_belongs_to_many :subscribers
>
> subscriber
> has_and_belongs_to_many :reports
>
> When I add a report to a subscriber, I have to run code like:
>
> raise "already there, idiot!" unless
> report.subscribers.find_by_id(subscriber_id).nil?
>
> Is there a better way to avoid adding duplicative associations?
> has_many
> :through seems like overkill for this application.
>
> Thanks
>
> --
> View this message in context: http://www.nabble.com/Preventing-Dups-
> in-HABTM-t1819715.html#a4961706
> Sent from the RubyOnRails Users forum at Nabble.com.
>
> _______________________________________________
> Rails mailing list
> Rails@lists.rubyonrails.org
> http://lists.rubyonrails.org/mailman/listinfo/rails