Skip to content

Instantly share code, notes, and snippets.

@lukesutton
Created October 1, 2008 02:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lukesutton/14005 to your computer and use it in GitHub Desktop.
Save lukesutton/14005 to your computer and use it in GitHub Desktop.
An issue with DM generating join models for HABTM
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
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
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