Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change the default polymorphic type-column name

I am using Ruby on Rails 3 and I would like to change the default type-column name used by a polymorphic association.

For example, if I have this class:

class Comment < ActiveRecord::Base
  ...
end

and I implement for that a polymorphic association, I would like to use the type-column names comm_id and comm_type instead of commentable_id and commentable_type. Is it possible? If so, what I have to change for the Comment class?

like image 308
user502052 Avatar asked May 06 '11 20:05

user502052


1 Answers

There's no way in Rails API to override the default column name used for polymorphic associations.

Take a look at this answer for a possible solution.

like image 64
simonwh Avatar answered Oct 18 '22 00:10

simonwh