I have two models class Ferm < AR::Base has_many :daily_analyses end class DailyAnalysis < AR::Base belongs_to :ferm end $ script/console Loading development environment (Rails 2.0.2)>> f = Ferm.find(:first)=> #<Ferm ... >>> f.daily_analysesNameError: uninitialized constant Ferm::DailyAnalyAsis from /Library/Ruby/Gems/1.8/gems/activesupport-2.0.2/lib/ active_support/dependencies.rb:478:in `const_missing'' from /Library/Ruby/Gems/1.8/gems/activerecord-2.0.2/lib/active_record/ base.rb:1750:in `compute_type'' from /Library/Ruby/Gems/1.8/gems/activerecord-2.0.2/lib/active_record/ reflection.rb:125:in `send'' from /Library/Ruby/Gems/1.8/gems/activerecord-2.0.2/lib/active_record/ reflection.rb:125:in `klass'' from /Library/Ruby/Gems/1.8/gems/activerecord-2.0.2/lib/active_record/ associations/has_many_association.rb:152:in `construct_sql'' from /Library/Ruby/Gems/1.8/gems/activerecord-2.0.2/lib/active_record/ associations/has_many_association.rb:6:in `initialize'' from /Library/Ruby/Gems/1.8/gems/activerecord-2.0.2/lib/active_record/ associations.rb:1032:in `new'' from /Library/Ruby/Gems/1.8/gems/activerecord-2.0.2/lib/active_record/ associations.rb:1032:in `daily_analyses'' from (irb):3 For some reason Rails is converting "daily_analyses" to "daily_analy_asis". Using the pluralizer and tableizer for "daily_analysis" correctly give "daily_analysis". Should I roll back my schema and rename the table something other than "daily_analysis?" Thanks --SH --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Hmmm, that''s weird. After successfully reproducing your problem, I added the following to config/initializers/inflections.rb Inflector.inflections do |inflect| inflect.singular ''daily_analyses'', ''daily_analysis'' end Now, in the console:>> "daily_analyses".singularize # returns "daily_analysis" >> "daily_analyses".classify #returns DailyAnalysisBut calling the association on Ferm still yields an error. :-O Giuseppe shenry wrote:> I have two models > > class Ferm < AR::Base > has_many :daily_analyses > end > > class DailyAnalysis < AR::Base > belongs_to :ferm > end > > $ script/console > Loading development environment (Rails 2.0.2) >>> f = Ferm.find(:first) > => #<Ferm ... > >>> f.daily_analyses > NameError: uninitialized constant Ferm::DailyAnalyAsis-- 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 -~----------~----~----~----~------~----~------~--~---
Giuseppe Bertini wrote:> Hmmm, that''s weird. > After successfully reproducing your problem, I added the following to > config/initializers/inflections.rb > > Inflector.inflections do |inflect| > inflect.singular ''daily_analyses'', ''daily_analysis'' > endShouldn''t that be inflect.singular ''analyses'', ''analysis'' ? --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
You can avoid inflection hassles entirely and just explicitly tell it which class to use: class Ferm < AR::Base has_many :daily_analyses, :class_name => "DailyAnalysis" end class DailyAnalysis < AR::Base belongs_to :ferm end -- 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 -~----------~----~----~----~------~----~------~--~---
with : Inflector.inflections do |inflect| inflect.irregular ''daily_analysis'', ''daily_analyses'' end I get ...>>"daily_analyses".classify=> "DailyAnalysis">>ferm.daily_analyses=> NameError: uninitialized constant Ferm::DailyAnalyAsis (...etc...)>>"daily_analyses".camelize=>"DailyAnalyses" # shouldn''t this camelize to ''DailyAnalysis''?>>"daily_analyses".camelize.classify=>"DailyAnalyAsis" it seems like when rails is putting together the Ferm::DailyAnalysis relationship it first camelizes "daily_analyses" into "DailyAnalyses" then classifies it incorrectly as "DailyAnalyAsis". I think I''ll just change my table name to something like "daily". SH --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
shenry wrote:> Inflector.inflections do |inflect| > inflect.irregular ''daily_analysis'', ''daily_analyses'' > endThat inflects too much. Did anyone try my suggestion? inflect.irregular ''analysis'', ''analyses'' It would be the same for ''daily_crisis'' to ''daily_crises''. (-: --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
@Philp, I tried your suggestion, same result as the other things I tried. @Max, Works great, very simple solution. Thanks, SH On Jun 17, 11:57 am, Phlip <phlip2...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> shenry wrote: > > Inflector.inflections do |inflect| > > inflect.irregular ''daily_analysis'', ''daily_analyses'' > > end > > That inflects too much. > > Did anyone try my suggestion? > > inflect.irregular ''analysis'', ''analyses'' > > It would be the same for ''daily_crisis'' to ''daily_crises''. (-:--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---