class Review::Comment < ActiveRecord::Base
belongs_to :thing
end
class Review::Thing < ActiveRecord::Base
has_many :comments, :class_name => ‘::Review::Comment’, :foreign_key
=> ‘thing_id’
end
Then we use the models in a view:
(I know it’s not clean to use the models directly in the view, but it is
simply an example
<% Comment.find(:all).each do |c| %>
<%= c.created_at %>
<% end %>
<% Review::Thing.find(:first).comments.each do |c| %>
<%= c.created_at %>
<% end %>
The following error arises:
SQLite3::SQLException: no such column: comments.thing_id: SELECT * FROM
“comments” WHERE (“comments”.thing_id = 1)
It happens because
“ActiveRecord::Base.compute_type(’::Review::Comment’)” returns class
“Comment” instead of class “Review::Comment”.
Additionally the following warning arises in the logs:
…/vendor/rails/activerecord/lib/active_record/base.rb:1910: warning:
toplevel constant Comment referenced by Review::Comment
Ok, so class_eval("::Review::Comment") in “compute_type” returns the
toplevel constant “Comment”, the wrong class!
Does anybody know why?
Is it a bug?
I attached a test project.
Thanks for your opinions!
the whole const_missing autoloading thing has a number of quirks.
Namespaced models aren’t used very often, at least in the past there
have been a number of edge cases.
A “require_dependency ‘review/comment’” on review/thing.rb solved the
problem! Do you agree when I say it is a hack?
Is ActiveRecord’s namespace support as bad?
the whole const_missing autoloading thing has a number of quirks.
Namespaced models aren’t used very often, at least in the past there
have been a number of edge cases.
Fred
Thanks Fred!
Should I open a feature request at http://rails.lighthouseapp.com or
does the rails core team provide a possibilty to vote for new features?