Polymorphic association inserts 0 instead of raising error when column is misconfigured as Integer
Posted
by zetetic
on Stack Overflow
See other posts from Stack Overflow
or by zetetic
Published on 2010-06-07T08:28:45Z
Indexed on
2010/06/07
8:32 UTC
Read the original article
Hit count: 180
ruby-on-rails
Here's one that stumped me for a while, though in retrospect it should have been obvious. I was getting the error message
NoMethodError: undefined method `constantize' for 0:Fixnum
when accessing a model through a polymorphic association. Turns out the table on the belongs_to
side of the association had an integer type
column instead of a string.
Easily fixed, but it seems like Rails ought to raise an error in this situation -- instead it happily adds the row with 0 in the type column.
© Stack Overflow or respective owner