Daniel Rikowski
Daniel Rikowski

Reputation: 72514

Can this STI structure be achieved in Rails?

I want to have these models:

AbstractArticle 
Article < AbstractArticle
FeaturedArticle < AbstractArticle

I want the name of the database table to be articles and not abstract_articles. (As the convention suggests)

Is this possible with Rails? How can I tell my base model to use a different table? Will STI still work even though the table name does not follow the convention?

Upvotes: 1

Views: 184

Answers (1)

Vlad Zloteanu
Vlad Zloteanu

Reputation: 8512

Yes, you can.

class AbstractArticle <  ActiveRecord::Base
  set_table_name :articles
end

http://wiki.rubyonrails.org/rails/pages/howtouselegacyschemas#using_set_table_name_for_table_names_outside_the_rails_convention

Upvotes: 3

Related Questions