#742 ✓resolved
Matt Aimonetti (mattetti)

Model.copy is broken

Reported by Matt Aimonetti (mattetti) | January 3rd, 2009 @ 10:06 PM

Article.copy(:legacy, :new) fails

The following code fixes the problem by using the repos properly:

module DataMapper
  module Model
    def copy(source, destination, query={})
      repository(destination) do
        repository(source).read_many(DataMapper::Query.new(repository(source), self, query)).each do |resource|

Comments and changes to this ticket

  • Dan Kubb (dkubb)

    Dan Kubb (dkubb) January 4th, 2009 @ 12:21 AM

    • Tag set to bug
    • State changed from “unconfirmed” to “resolved”

    This should be resolved as of the following commit:


    There's a couple of performance tweaks to get around lazy field initialization:

    • We use the :fields query option to only retrieve fields that are in both destinations. This could be significant if the source had a Text field, while the destination does not. We can skip fetching the Text field if it is not needed.

    • By explicitly specifying the :fields, we eager load all the lazy properties we do care to copy. Without this you might be incurring extra penalties lazily loading stuff that is not normally returned by Model#all.

    • Resource#attributes will lazily load all the properties in the Model that were not loaded, so bypassing it is necessary.

  • Shane Hanna

    Shane Hanna January 4th, 2009 @ 06:26 PM

    Can the following ticket be resolved as well then?


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 »


Referenced by