Xanothos
2009-Dec-26 14:46 UTC
Does :class_name for belongs_to have to be a string and why?
Seemingly, when I use a symbol, I get an ActiveRecord error stating ''Can''t convert symbol into String.'' Why can''t I use a symbol here? Possibly this is a deeper misunderstanding of symbols in general on my part. #ActiveRecord error class Book < ActiveRecord::Base belongs_to :author, :class_name => :Person, :foreign_key => :author_id end #works class Book < ActiveRecord::Base belongs_to :author, :class_name => "Person", :foreign_key => :author_id end -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Frederick Cheung
2009-Dec-26 17:29 UTC
Re: Does :class_name for belongs_to have to be a string and why?
On Dec 26, 3:46 pm, Xanothos <xanot...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Seemingly, when I use a symbol, I get an ActiveRecord error stating > ''Can''t convert symbol into String.'' Why can''t I use a symbol here? > Possibly this is a deeper misunderstanding of symbols in general on my > part.Well symbols and strings are not interchangeable in general (and glancing briefly at the source, activerecord calls various methods only available on strings on the :class_name option). Fred> > #ActiveRecord error > class Book < ActiveRecord::Base > belongs_to :author, :class_name => :Person, :foreign_key > => :author_id > end > > #works > class Book < ActiveRecord::Base > belongs_to :author, :class_name => "Person", :foreign_key > => :author_id > end-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@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.
Pale Horse
2009-Dec-26 22:47 UTC
Re: Does :class_name for belongs_to have to be a string and
... and you capitalised the symbol for ":Person". -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Xanothos
2009-Dec-27 05:08 UTC
Re: Does :class_name for belongs_to have to be a string and
Shouldn''t the symbol be capitalized _if_ it worked in this scenario? The class name is capitalized, ie: class name = Person therefore: p Person.new. Why would the symbol be lowercase? On Dec 26, 5:47 pm, Pale Horse <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> ... and you capitalised the symbol for ":Person". > -- > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@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.