Let''s start with an example: --- class Comment < ActiveRecord::Base end # dummy (to invent a "table namespace") class Review < ActiveRecord::Base end # ... dummy # is "review_comments" in the database 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 %> <hr/> <% 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! der Flo Attachments: http://www.ruby-forum.com/attachment/2820/2_models_test.zip -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Frederick Cheung
2008-Oct-16 09:37 UTC
Re: 2 Models: Same name, different namespace => Problems
On Oct 16, 10:27 am, Florian Dütsch <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> Let''s start with an example: > > > 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? >There''s some funkyness to do with the automatic loading and namespaces (see http://groups.google.com/group/rubyonrails-core/browse_thread/thread/17e9e5e564e8ea64/def2cec288984fa3?lnk=gst&q=const_missing#def2cec288984fa3) You may be able to sidestep this by just using require_dependency to require stuff ahead of time Fred --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Florian Dütsch
2008-Oct-16 11:17 UTC
Re: 2 Models: Same name, different namespace => Problems
Frederick Cheung wrote:> On Oct 16, 10:27�am, Florian D�tsch <rails-mailing-l...@andreas-s.net> > wrote: >> Does anybody know why? >> Is it a bug? >> > There''s some funkyness to do with the automatic loading and namespaces > (see > http://groups.google.com/group/rubyonrails-core/browse_thread/thread/17e9e5e564e8ea64/def2cec288984fa3?lnk=gst&q=const_missing#def2cec288984fa3) > You may be able to sidestep this by just using require_dependency to > require stuff ahead of time > > FredHi Fred! 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? Thanks, der Flo -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Frederick Cheung
2008-Oct-16 14:39 UTC
Re: 2 Models: Same name, different namespace => Problems
On 16 Oct 2008, at 12:17, Florian Dütsch wrote:> > Frederick Cheung wrote: >> On Oct 16, 10:27�am, Florian D�tsch <rails-mailing-l...@andreas- >> s.net> >> wrote: >>> Does anybody know why? >>> Is it a bug? >>> >> There''s some funkyness to do with the automatic loading and >> namespaces >> (see >> http://groups.google.com/group/rubyonrails-core/browse_thread/thread/17e9e5e564e8ea64/def2cec288984fa3?lnk=gst&q=const_missing#def2cec288984fa3) >> You may be able to sidestep this by just using require_dependency to >> require stuff ahead of time >> >> Fred > Hi Fred! > > 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 --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Florian Dütsch
2008-Oct-17 07:28 UTC
Re: 2 Models: Same name, different namespace => Problems
Frederick Cheung wrote:> On 16 Oct 2008, at 12:17, Florian Dütsch wrote: > >>> (see >> > 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. > > FredThanks 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? Bye, der Flo -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Frederick Cheung
2008-Oct-17 08:04 UTC
Re: 2 Models: Same name, different namespace => Problems
On Oct 17, 8:28 am, Florian Dütsch <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> Frederick Cheung wrote: > > On 16 Oct 2008, at 12:17, Florian Dütsch wrote: > > >>> (see > > > 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 athttp://rails.lighthouseapp.comor > does the rails core team provide a possibilty to vote for new features? >You might want to post to the rubyonrails-core google group. Although like I said, last time this was discussed it wasn''t clear what to do about it. Fred> Bye, > der Flo > -- > Posted viahttp://www.ruby-forum.com/.--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---