Matthew Hensrud
2013-Mar-28 02:48 UTC
Rationale for HMT << writing multiple join records instead of checking for an existing?
Hey all- Just curious - in my app I have a membership schema that uses a join table which holds some settings (like active / archived, etc) on the status of the membership. Trying to use the association HMT helper methods properly, I was adding people to the collection using << But.. in my app, I need to allow people to add many members at once, and one option is using a CSV file, so I want to be prepared for the possibility of adding the same member multiple times, etc.. so I was dismayed to discover that using << will create identical join records in the database if the same object is added more than once. Now, for the "return" that''s fine, uniq: true gets me the right values.. but since i need to work with the join table itself from time to time, having multiple records is a non-starter. I''m guessing << was meant to be pretty quick-n-dirty, but it seems a little TOO dirty (from a data perspective) in a HMT context — shouldn''t << have a little more intelligence built in so as not to dirty up ones database? I''m just checking for the object''s existence now before adding, but my instincts told me that << on an existing object would be ignored instead of executed. Thoughts? Maybe I''m missing something dumb. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-core+unsubscribe@googlegroups.com. To post to this group, send email to rubyonrails-core@googlegroups.com. Visit this group at http://groups.google.com/group/rubyonrails-core?hl=en. For more options, visit https://groups.google.com/groups/opt_out.