How to prevent derived model from Single Table Inheritance in Rails 3.2.13 and how to convert inherited model object as derived model object

StackOverflow https://stackoverflow.com/questions/21233761

Вопрос

I've three models User, Group, Employee. Implemented Single Table Inheritance between User and Group model. But I don't want single table inheritance in Employee model which inherits User model but want to convert User model object as Employee model object. I achieved it by adding a piece of code, self.inheritance_column = :_type_disabled in Employee model and by calling the becomes() method on User object. It works in Rails 3.2.8 but not working in Rails 3.2.13 version.

Exception is:

NoMethodError (undefined method `_type_disabled=' for #<Employee:0xb429428>)

Code snippet is:

class Employee < User

  self.inheritance_column = :_type_disabled

  def self.current

    User.current.becomes(self)

  end

  .
  .
  .
  .
  .
 end

Please give me a solution to achieve this in Rails 3.2.13 too. Thanks in advance!

Это было полезно?

Решение

I got the answer from my friend, we just need to define as virtual attribute in corresponding Model (In my case, Employee Model)

attr_accessor :_type_disabled
self.inheritance_column = :_type_disabled
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top