Skip to content

Commit

Permalink
[merb_datamapper] define lazy properties after models were loaded
Browse files Browse the repository at this point in the history
* This is necessary because dm automatically defines appropriate
  FK properties for m:1 and 1:1 relationships, if the respective
  FK property wasn't explicitly defined by the programmer.
  • Loading branch information
snusnu authored and wycats committed Sep 17, 2009
1 parent 7e1a27d commit 84f5fc2
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions lib/merb_datamapper.rb
Expand Up @@ -63,18 +63,15 @@ class Merb::Orms::DataMapper::Associations < Merb::BootLoader
after LoadClasses

def self.run
Merb.logger.verbose! 'Merb::Orms::DataMapper::Associations block'

# make sure all relationships are initialized after loading
descendants = DataMapper::Resource.descendants.dup
descendants.dup.each do |model|
descendants.merge(model.descendants) if model.respond_to?(:descendants)
end
descendants.each do |model|
Merb.logger.verbose! 'Merb::Orms::DataMapper::Associations - defining lazy relationship properties'

DataMapper::Model.descendants.each do |model|
model.relationships.each_value { |r| r.child_key }
end

Merb.logger.verbose! 'Merb::Orms::DataMapper::Associations complete'
Merb.logger.verbose! 'Merb::Orms::DataMapper::Associations - complete'

end
end

Expand Down

0 comments on commit 84f5fc2

Please sign in to comment.