On Feb 18, 3:07 pm, Shawn <svicalifor...@gmail.com> wrote: > It appears that if someone adds object twice to the same association, > it will be added twice to the target association cache: > > # Add the given associated object to the given association > def add_associated_object(opts, o) > raise(Sequel::Error, "model object #{model} does not have a > primary key") unless pk > raise(Sequel::Error, "associated object #{o.model} does not have > a primary key") if opts.need_associated_primary_key? && !o.pk > return if run_association_callbacks(opts, :before_add, o) == > false > send(opts._add_method, o) > ==> associations[opts[:name]].push(o) if associations.include?(opts > [:name]) > ## WOULD ADD HERE: && !associations[opts[:name]].include?(o) > add_reciprocal_object(opts, o) > run_association_callbacks(opts, :after_add, o) > o > end > > Shouldn't there be some logic on the marked line above to check if the > cache already contains object o?
That makes some amount of sense for one_to_many associations, but many_to_many associations allow you to associate two objects to each other multiple times, so it doesn't make sense for them (unless the :uniq option is used). I'd consider a patch that respected that. If you want to do so, add a method (unique?) to the AssociationReflection classes that's true for one_to_many and false for many_to_many unless :uniq is set, and change the code to use it. Jeremy --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "sequel-talk" group. To post to this group, send email to sequel-talk@googlegroups.com To unsubscribe from this group, send email to sequel-talk+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sequel-talk?hl=en -~----------~----~----~----~------~----~------~--~---