Re: Unnecessary exception raised in AS::Dependencies.load_missing_constant

Andrew White
2010-02-15T14:15:31Z

On 15 Feb 2010, at 13:31, Yehuda Katz wrote:

> I wouldn''t. I consider Rails'' lookup from disk to be an
alternate form of constant lookup, and I''d want it to use semantics
that are identical to Ruby''s semantics:
>
> class Foo::Bar
>   Baz
>   # normal Ruby: will search Foo::Bar::Baz and Object::Bar
>   # rails: will search Foo::Bar::Baz, Foo::Baz, and Object::Baz
> end
>
> This discrepancy means that the behavior could be different depending on
whether autoload is in effect (for instance, if all constants are preloaded, and
autoload is turned off, the behavior would be different than when it was on).
I''m not happy about that, and would remove the discrepancy if possible.

Following the Ruby semantics will mean that this will never work:

class Admin::Account < ActiveRecord::Base
  has_many :users
end

You''ll always have to specify the class on the association:

class Admin::Account < ActiveRecord::Base
  has_many :users, :class_name => "Admin::User"
end

My aesthetic sense rejects this as a solution :-)

The alternative is to implement a custom constant lookup system within
ActiveRecord which we probably don''t want to do.


Andrew White