While playing with Rails and ActiveRecord with has_many :through associations found an interesting error
> Account.find :all
SyntaxError: compile error
/usr/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active_record/base.rb:1748: syntax error, unexpected tINTEGER
It took me some time to figure this out so I thought it might be useful to post it here, maybe someone has the same problem.
The error is because of the ‘type’ attribute of Account model, in Rails it is reserved for single table inheritance. To fix this just do not use an attribute called ‘type’, rename it to something else.
Thank you, you saved my life!!
Comment by Anand Chhatpar — January 26, 2008 @ 9:41 pm
Thank you, for saving my time!
Comment by Egg — February 23, 2008 @ 5:26 pm
That’s a good an simple answer, thanks.
Comment by xvaib — April 11, 2008 @ 5:40 pm
Thanks! Helped.
Comment by Matthew J Mucklo — May 27, 2008 @ 10:41 pm
Sweet! This is the exact problem I was having. Couldn’t figure it out for the life of me. It would be nice if it gave an error message like “Don’t use ‘type’, it is reserved”. I too was using a has_many :through, but removing it didn’t fix it, so I assume that it was just a coincidence and had nothing to do with the error. Thanks for the post!
Comment by Trevor Evans — July 18, 2008 @ 7:50 pm