#727 ✓resolved
Flip Sasser

[PATCH] Many-to-Many "Cannot find the child_model `whatever`"

Reported by Flip Sasser | December 23rd, 2008 @ 12:51 PM

Hey guys,

Found this bug when using some Merb slices. If I namespace a child model inside a module with all caps, the through relationship created on a has n,:through => Resource gets broken because of some inflection rules. Here's the example:


class ACL::Role
  include DataMapper::Resource
  property :id,Serial
  property :name,String,:length => 32,:nullable => false,:unique => true
  property :omnipotent,Boolean

  has n,:users,:through => Resource
end

will throw an error:


Cannot find the child_model AclRoleUser for ACL::Role

It turns out DataMapper creates a great join model name (ACLRoleUser), but then builds the join relationship like so:


model.has(model.n, opts[:near_relationship_name])

Unfortunately, that means "ACL::Role has n :acl_role_users" which infers from the passed in name that the child_model should be something named AclRoleUser. Which is different from ACLRoleUser.

So! Patch attached, but here's all it does:


model.has(model.n, opts[:near_relationship_name],:class_name => model_name)

Flip

Comments and changes to this ticket

  • Dan Kubb (dkubb)

    Dan Kubb (dkubb) January 8th, 2009 @ 05:18 AM

    • State changed from “unconfirmed” to “accepted”
    • Assigned user set to “Dan Kubb (dkubb)”
  • Dan Kubb (dkubb)

    Dan Kubb (dkubb) February 23rd, 2009 @ 03:32 PM

    • State changed from “accepted” to “hold”

    Flip, would you mind trying this with the dm-core/next branch? I've changed some of the inflection and handling of the join model when using namespaced models. I think it may have solved your problem, but without knowing the structure of your ACL::User model I can't reproduce your problem locally.

  • Flip Sasser

    Flip Sasser March 18th, 2009 @ 03:15 PM

    Hi Dan,

    Just saw this response. Here's the model (inside a merb slice named a_c_l):

    
    class ACL::Role
      include DataMapper::Resource
      property :id,Serial
      property :name,String,:length => 32,:nullable => false,:unique => true
      property :omnipotent,Boolean
      has n,:permissions
      has n,:users,:through => Resource
    end
    

    ... and my user model:

    
    class User
      include DataMapper::Resource
      property :id,Serial
      property :first_name,String,:length => 64
      property :last_name,String,:length => 64
      property :email,String,:length => 128,:nullable => false,:unique => true
      property :password,String,:length => 64
      property :active,Boolean,:default => true
      property :admin,Boolean
      property :authenticates,Boolean,:default => true
      property :change_password,Boolean
    end
    

    As of core 0.9.10 it's still happening - I'll try the latest this evening and let you know.

    Flip

  • Dan Kubb (dkubb)

    Dan Kubb (dkubb) June 7th, 2009 @ 03:36 AM

    • State changed from “hold” to “resolved”

    I can confirm this problem is resolved in the dm-core/next branch.

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 »

Attachments

Pages