addressalign-toparrow-leftarrow-rightbackbellblockcalendarcameraccwchatcheckchevron-downchevron-leftchevron-rightchevron-small-downchevron-small-leftchevron-small-rightchevron-small-upchevron-upcircle-with-checkcircle-with-crosscircle-with-pluscrossdots-three-verticaleditemptyheartexporteye-with-lineeyefacebookfolderfullheartglobegmailgoogleimageimagesinstagramlinklocation-pinmagnifying-glassmailminusmoremuplabelShape 3 + Rectangle 1outlookpersonplusprice-ribbonImported LayersImported LayersImported Layersshieldstartickettrashtriangle-downtriangle-uptwitteruseryahoo

Re: [ruby-81] copying and comparing model objects

From: user 5.
Sent on: Tuesday, March 4, 2008 11:20 AM
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])
>  http://ruby.meetu...­
>  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
>
>

Our Sponsors

People in this
Meetup are also in:

Sign up

Meetup members, Log in

By clicking "Sign up" or "Sign up using Facebook", you confirm that you accept our Terms of Service & Privacy Policy