Created
October 1, 2008 02:05
-
-
Save lukesutton/14005 to your computer and use it in GitHub Desktop.
An issue with DM generating join models for HABTM
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
NameError: wrong constant name MelonTest::Jam | |
from /opt/local/lib/ruby/gems/1.8/gems/dm-core-0.9.6/lib/dm-core/associations/many_to_many.rb:60:in `const_defined?' | |
from /opt/local/lib/ruby/gems/1.8/gems/dm-core-0.9.6/lib/dm-core/associations/many_to_many.rb:60:in `setup' | |
from /opt/local/lib/ruby/gems/1.8/gems/dm-core-0.9.6/lib/dm-core/associations.rb:122:in `has' | |
from ./assoc_test.rb:8 | |
from /opt/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `gem_original_require' | |
from /opt/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `require' | |
from (irb):2 | |
from :0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'dm-core' | |
module Test | |
class Jam | |
include DataMapper::Resource | |
property :id, Serial | |
has n, :melons, :through => Resource | |
end | |
class Melon | |
include DataMapper::Resource | |
property :id, Serial | |
has n, :jams, :through => Resource | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
The anonymous join model created by ManyToMany#setup will be be generated | |
from the classname of each of the models, prefixed with the module name. | |
So the classes Test:Jam and Test::Melon would have an anonymous join model | |
called TestJamTestMelon. | |
This would then also account for models living in different modules i.e. | |
Test::Jam and Wrong::Smell would have a join model called TestJamWrongSmell | |
Using a naming scheme like this would also ensure that the table names are | |
unambiguous and unlikely to collide with any others. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment