
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|
self.create(resource.attributes)
end
end
end
end
end
Comments and changes to this ticket
-
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:
http://github.com/sam/dm-core/co...
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.
-
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.
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
Tags
Referenced by
-
695 attributes= now respects method visibility change breaks Model#copy Ticket #742 is a dupe of this, and is now resolved.
-
695 attributes= now respects method visibility change breaks Model#copy My mistake, ticket #742 doesn't resolve the protected att...