Really? Despite namespace models have an issue, wouldn't this just be bad in general for all sorts of other reason? What if the model it chose was in a namespace for a plugin or something else vendor related?

It just seems to me that despite weather namespacing a models are present the assumed constant for the declaration would do what is expected. Is the fix crazy or simple?

 - Ken

On Mar 16, 2009, at 7:34 PM, Ryan Angilly wrote:

I would say leave it alone for now. It does seem weird that it chooses the non-obvious one each time, but some of the big wigs have voiced opinions against the idea of namespacing models in general. And their arguments make sense.

http://m.onkey.org/2007/12/9/namespaced-models
http://stackoverflow.com/questions/601768?sort=oldest
http://www.strictlyuntyped.com/2008/08/activerecord-can-haz-namespaces.html


On Mon, Mar 16, 2009 at 6:16 PM, José Valim <[email protected]> wrote:

Hi guys,

Before opening a ticket, I want to be sure if this is a bug or not.
Example:

 class User < ActiveRecord::Base
 end

 class Admin::User < ActiveRecord::Base
 end

And then:

 class Account < ActiveRecord::Base
   belongs_to :user
 end

When I was calling Account.new.build_user, it was trying to create a
new Admin::User because the default class_name is just "User". To fix
the problem, I had to do:

 class Account < ActiveRecord::Base
   belongs_to :user, :class_name => '::User'
 end

It also has problems in the opposite way:

 class User < ActiveRecord::Base
 end

 class Admin::User < ActiveRecord::Base
 end

And then:

 class Admin::Account < ActiveRecord::Base
   belongs_to :user
 end

Sometimes Admin::Account.build_user is trying to build a ::User and
other times ::Admin::User, because, again the default class_name is
just "User".

My opinion is that in the first case, the class name should be by
default "::User" and in the second it should be "::Admin::User".

The thing is, since the patch comes in, it will break apps that are
relying in this wrong behavior. The good point is that the error will
be raised when the application starts. The way it's now, takes quite
sometime for you to discover that Account was trying to build a
Admin::User instead of User.

Are you in or out for this change?

Regards,

José Valim.



--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-core?hl=en
-~----------~----~----~----~------~----~------~--~---


Attachment: smime.p7s
Description: S/MIME cryptographic signature

Reply via email to