I was noticing that to update a has_many association, Rails uses the following:
begin
delete from tagpairs where id = 33;
delete from tagpairs where id = 34;
delete from tagpairs where id = 35;
...
insert into tagpairs (...) values (...);
insert into tagpairs (...) values (...);
...
commit
This would be better as:
delete from tagpairs where obj_type = ''guidepage'' and
obj_id = 1;
insert into tagpairs (...) values (...);
...
In my case, I''m using a polymorphic association. However, the basic
idea applies to a non-polymorphic association. We can and should delete members
of the association based on the association key field having a certain value
rather than deleting specific ids. Also, notice how this means that we
don''t necessarily have to store the ''id'' field,
which, for my application, is redundant.
Cs
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
http://wrath.rubyonrails.org/pipermail/rails/attachments/20060718/0de9c114/attachment.html