They're only editing @model.attributes, really, so just .dup the
hashes and use Hash#diff recursively. No?
On 3/4/08, Loqi <[address removed]> wrote:
> This seems like something that should be trivial, but I'm not
> satisfied with any of the solutions I've tried.
> I want to read an Active Record model into two identical memory
> objects, allowing the user to edit one of them. Then when it comes
> time to write, I'll compare the two objects' data, only updating the
> DB if there's been a change.
> The easiest way to deep-copy DB models is to simply find() them
> twice, but that's just wrong. Serializing the object with Marshal
> would work for copying, but it's unsatisfying, and comparing two
> serializations seems as though it would cause false negatives. I
> could roll my own recursive copy and compare methods, and attaching
> them to ActiveRecord::Base or to Object, but this is probably
> something that's already been done better by someone else.
> Any ideas on a hassle-free way to do a deep copy and deep compare on
> two model objects?
> Please Note: If you hit "REPLY", your message will be sent to everyone on this mailing list ([address removed])
> This message was sent by Loqi ([address removed]) from The East Bay Ruby Meetup Group.
> To learn more about Loqi, visit his/her member profile: http://ruby.meetu...
> To unsubscribe or to update your mailing list settings, click here: http://www.meetup...
> Meetup.com Customer Service: [address removed]
> 632 Broadway New York NY 10012 USA