#164 ✓resolved
Dru Nelson

Model doesn't copy attribs when instantiated from another model

Reported by Dru Nelson | February 21st, 2008 @ 04:49 PM

When using two database objects (as shown in the sample, in the documentation), it should be possible

to do (roughly) the following:

DataMapper::database(:default) do

class Cat < Datamapper::Base



cat = Cat.first

DataMapper::database(:dest_db) do

class Cat2 < Cat

... # same properties as above


cat2 = Cat2.new( cat )




I did this when migrating a database from Postgres

to MySQL (DM was very handy for this).

After scratching my head for a while, I found that the

DM code was broken in this case.

I have attached a patch to the spec and the persistence.rb files to fix this.


Comments and changes to this ticket

  • Dan Kubb (dkubb)
  • Sam Smoot

    Sam Smoot May 2nd, 2008 @ 04:53 AM

    • Assigned user set to “Mike Mayo”

    The problem appears to be that details.respond_to?(:persistent?) in #initialize_with_attributes should actually be details.class.respond_to?(:persistent?) like in your patch.

    But no need to change the rest.

    So Mike, please checkout DM-SVN from Rubyforge and make that change in the initialize_with_attributes method.

    Also, paste in Dru's spec to the persistence_specs and make sure it passes please.

  • Sam Smoot

    Sam Smoot May 8th, 2008 @ 04:38 PM

    • Assigned user changed from “Mike Mayo” to “Adam French”

    Adam, PDI.

  • Adam French

    Adam French May 8th, 2008 @ 05:13 PM

    • State changed from “new” to “resolved”

    done and done.

    ends up the #=== method was directional, so I adjusted the case statement a little bit and we're good to go.

    Thanks for a good bug report, Dru!

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.

New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

People watching this ticket