#150 ✓resolved
Emmanuel Surleau (Mercurial Alchemist)

DataMapper not working with models that are part of a module

Reported by Emmanuel Surleau (Mercurial Alchemist) | February 8th, 2008 @ 03:01 PM

DataMapper breaks when using models like 'ModuleName::Module' due to some code using non-recursive versions of const_defined? and const_get. I've attached a patch solving the issue.

Comments and changes to this ticket

  • Michael Boutros

    Michael Boutros February 10th, 2008 @ 08:22 PM

    Emmanuel, I don't see where you would use this? I'm sure there is a reason, I just can't seem to figure it out. Regardless, the patch applies cleanly, but a) due to my thickness, I don't know what tests to write for this, and b) I'm not sure we should include the credit to Logan. It'll just get taken out one day, and since he posted it to a mailing list I'm sure he won't mind us using it.

    But other than that, it definitely didn't break anything!

  • Emmanuel Surleau (Mercurial Alchemist)

    Emmanuel Surleau (Mercurial Alchemist) February 11th, 2008 @ 02:24 AM


    Thanks for your quick answer. I have uploaded some simple code which shows the problem. Basically, without the patch, you cannot use something like:

    :has_one :accessor_name, :class => 'ModuleName::ClassName'

    I'll be sure to include an rspec test next time, just don't quite have time to write it this morning :)

  • Michael Boutros

    Michael Boutros February 11th, 2008 @ 03:59 PM

    Yep, that definitely broke before, but your patch fixes it up. I refactored it a little bit and added a test. The patch is also for git, so if you're using SVN you might have to manually do the edits.

  • Adam French

    Adam French February 11th, 2008 @ 06:46 PM

    • State changed from “new” to “open”


    does that :has_one association work when you pass :class as a Class, not a string? I'm thinking that strings get sent through the inflector and things fail because it attempt to singularize it to ModuleName::ClassNam

  • Emmanuel Surleau (Mercurial Alchemist)

    Emmanuel Surleau (Mercurial Alchemist) February 12th, 2008 @ 01:14 AM

    Michael, thanks for incorporating this change.

    Adam, I didn't even know you pass a class directly. Unfortunately, the

    error stack goes like this:

            from ./../data_mapper/lib/data_mapper/dependency_queue.rb:15:in `resolve!'
            from ./../data_mapper/lib/data_mapper/dependency_queue.rb:14:in `each_pair'
            from ./../data_mapper/lib/data_mapper/dependency_queue.rb:14:in `resolve!'
            from ./../data_mapper/lib/data_mapper/dependency_queue.rb:10:in `add'

    If you use a Class directly, the method 'associated_constant_name' will

    take it and return the name of the class. It's the result of this method which gets passed to 'add'. By the way, looking at the code (unless I'm missing something), it seems a bit silly to do Class -> String (in HasNAssociation#associated_constant_name) -> Class (in DependencyQueue#resolve!).

    While looking at HasNAssociation#associated_constant_name, I noticed another, unrelated issue. The :class and :class_name parameters are equivalent, which means that :class_name => MyClassObject works. I'd suggest that DM should assume that :class is a Class object, and :class_name is a String object. Maybe add a type check when retrieving :class, and print a meaningful error message if it's a String.

    Just my two cents.

  • Sam Smoot

    Sam Smoot March 17th, 2008 @ 10:42 AM

    So wait, is this applied or not? Should it be closed out?

  • Dan Kubb (dkubb)
  • Sam Smoot

    Sam Smoot April 27th, 2008 @ 10:59 PM

    • State changed from “open” to “resolved”

    Ok, I'm going to assume this is resolved since that's what it sounds like. If not, feel free to reopen the 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 »