
Namespaced models break associations
Reported by Yaroslaff Fedin | April 13th, 2008 @ 02:21 PM
Say, I have namespaced model `Forums::Topic`.
I define association like:
`has :posts, 0..n, :class_name => "Forums::Post".`
Then, if I try to do something like:
`Forums::Topic.first.posts`
I get:
`unitialized constant DataMapper::Support::Object::Post`
which is obviously a result of demodulizing the class name at line 14 of one_to_many.rb. If i fix that line to avoid demodulization, it breaks foreign_key guessing.
Comments and changes to this ticket
-
Postmodern April 13th, 2008 @ 07:04 PM
With datamapper 0.3.0 and using :class I got a "wrong constant name Namespace::Stuff" exception from /usr/lib64/ruby/gems/1.8/gems/datamapper-0.3.0/lib/data_mapper/dependency_queue.rb:15:in `const_defined?'
Perhaps Kernel#instance_eval should be used instead of Object.const_get.
-
Yaroslaff Fedin April 14th, 2008 @ 08:01 AM
I was talking about 0.9, not sure about 0.3.
But actually, to check a namespaced model you should call const_get from namespace like:
Object.const_get(Namespace) && Namespace.const_get(Stuff)
IIRC :)
-
Dan Kubb (dkubb) April 14th, 2008 @ 05:17 PM
- Milestone cleared.
- State changed from new to open
-
Guy van den Berg (guyvdb) April 15th, 2008 @ 03:03 AM
The issue here is a mixture between the NamingConvention and DM::Inflection. The default NamingConvention is UnderscoredAndPluralized which does a:
DataMapper::Inflection.pluralize(
DataMapper::Inflection.underscore(value)
)
If you look at the DM::Inflector#underscore it replaces :: with /.
I added a NamingConvention UnderscoredAndPluralizedWithoutModule some time ago which calls does:
DataMapper::Inflection.pluralize(
DataMapper::Inflection.underscore(
DataMapper::Inflection.demodulize(value)
)
)
basically removing the module name. The fix is simple... we just need to decide how we want to name tables by default.
What should Formum::Post table name be? forum_posts ?
-
Guy van den Berg (guyvdb) April 15th, 2008 @ 03:04 AM
My comment above was spaced so the code was readable but LH stripped away my leading spaces - sorry about that
-
Guy van den Berg (guyvdb) April 15th, 2008 @ 03:30 AM
Pushed a fix that names tables module_module_resouce_plural by default. Forum::Post will become forum_posts
-
Dan Kubb (dkubb) April 15th, 2008 @ 03:31 AM
- State changed from open to resolved
-
Yaroslaff Fedin April 15th, 2008 @ 09:57 AM
Please, reopen this ticket. It's not duplicate with #202 and the mentioned fix doesnt handle what's stated in ticket which is not easily fixable.
-
Dan Kubb (dkubb) April 15th, 2008 @ 10:34 AM
- State changed from resolved to open
-
David Leal April 15th, 2008 @ 12:18 PM
- Assigned user set to David Leal
-
Sam Smoot June 2nd, 2008 @ 04:56 PM
- Milestone cleared.
-
Bernerd Schaefer July 10th, 2008 @ 09:50 AM
- State changed from open to resolved
- Tag set to bug, class, namespace
This appears to be working in edge dm (http://pastie.org/private/coshum.... I'm going to go ahead and mark this resolved.
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
Referenced by
-
202 Datamapper doesnt handle namespaced models well This is a duplicate of #203
-
202 Datamapper doesnt handle namespaced models well The fix for this, is in http://wm.lighthouseapp.com/proj...