#510 ✓resolved
Postmodern

DataMapper fails to load has-many relations after auto_upgrade!

Reported by Postmodern | August 16th, 2008 @ 11:20 PM

After DataMapper.auto_upgrade! is called all of my models only contain their first has-many relation. This behavior appears to be related to DataMapper's lazy-loading of has-many relations. I've found that adding the following code before the the auto_upgrade! call causes all has-many relations to be loaded.


# sourced from http://gist.github.com/3010
descendants = DataMapper::Resource.descendants.dup
descendants.each do |model|
  descendants.merge(model.descendants) if model.respond_to?(:descendants)
end
descendants.each do |model|
  model.relationships.each_value { |r| r.child_key if r.child_model == model }
end

# make sure the repository is properly setup
DataMapper.auto_upgrade!

Comments and changes to this ticket

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

Pages