Is this a bug in ActiveRecord or expected to work this way?

Hi,

I used “type” as a column in “rails generate model” there was no error.

I did a rake db:migrate again no problem.

I created the values using console again no problem.

I did a show function in users contoller then rails threw up the error.
But
should it not give this error right at the time of generate
model or db:migrate or atleast create.

ActiveRecord::SubclassNotFound in UsersController#show

The single-table inheritance mechanism failed to locate the subclass:
‘student’. This error is raised because the column ‘type’ is reserved
for
storing the class in case of inheritance. Please rename this column if
you didn’t intend it to be used for storing the inheritance class or
overwrite
User.inheritance_column to use another column for that information.

On 22 February 2011 06:15, Bhasker H. [email protected]
wrote:

Hi,

I used “type” as a column in “rails generate model” there was no error.

ActiveRecord::SubclassNotFound in UsersController#show

“Type” is a reserved word in Rails (the wiki seems to be not
responding, but there’s still a few references around):

http://juicebar.wordpress.com/2007/05/30/reserved-words-in-rails/

I did a show function in users contoller then rails threw up the error. But
should it not give this error right at the time of generate
model or db:migrate or atleast create.

At neither of those times is ActiveRecord doing anything with the
model (unless you’re accessing your model in your migration…) so it
wouldn’t cause an error until you try to instanciate an object.

Hi,

Is it not accessing the model at the time of

$rake db:migrate.

Is there anything like a cheat sheet for rails ?

Actually I found one but that did not have “type” as a reserved word.

Regards,

On 22 Feb 2011, at 06:57, Bhasker H. [email protected]
wrote:

Hi,

Is it not accessing the model at the time of

$rake db:migrate.

It won’t be instantiating any model objects at that point. Besides, it’s
completely legal to create a model with a column called type, it’s just
that activerecord makes assumptions about what is going to be in that
column

Fred

On 22 February 2011 06:57, Bhasker H. [email protected]
wrote:

Is it not accessing the model at the time of

$rake db:migrate.

Not unless you’ve written some code in the migration to do so.

Is there anything like a cheat sheet for rails ?

There certainly are things like cheatsheets for Rails. I gave you a
link already to one reference, which had other links in it
(specifically, to the Rails wiki, which does not seem to be responding
at the moment), but if you Google your phrase “cheat sheet for rails”
you will get lots of results.

Actually I found one but that did not have “type” as a reserved word.

Trust us, it is… you’ve discovered that yourself already :slight_smile:
Rails uses it to determine STI class type. Just change your fieldname
for now, and all will be good.

You application crashed because you probably have a user of type
“student” but you don’t have a matching class for it. As others
explained the migrations and model generations don’t use single table
inheritance, so they won’t crash on it. Furthermore the generators don’t
know which types you want to use in your application, you have to create
these manually as new models

If you look at the ActiveRecord::Base API documentation
(http://api.rubyonrails.org/classes/ActiveRecord/Base.html) and scroll
down to the section on “Single Table Inheritance” you’ll see what single
table inheritance is about.

If you want to know more about Rails’ API then you can find all of the
API documentation for Rails here: http://api.rubyonrails.org/
You can also get some valuable information from the Rails Guides too:
http://guides.rubyonrails.org/

I did not see the other links in the main link.

I have changed already. But I wanted the link to avoid such mistakes in
the
future.

Thanks & Regards,

Hi Mark,

Thanks, yeah latter I saw that.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs