Hi, I am trying to use polymorphic associations to solve the following
I want a general class ‘Employee’ which content can come from 2 other
The code is:
class Employee < ActiveRecord::Base
:assignable is the interface we expose to mask of various employee
belongs_to :assignable, :polymorphic => true
class User < ActiveRecord::Base
has_many :employees, :as => :assignable #here I am not sure if I should
put has_many or has_one ?
class Secretary < ActiveRecord::Base
has_many :employees, :as => :assignable
In Read mode, everything is fine :
Employee.find(:first).class # => Employee.
Employee.find(:first).assignable.class # => User or Secretary ,
depending on the data.
Now, I am writing my Unit Tests and I want to see if when I create a
User, the Employee entry is also created or not.
Apparently, User.save does not create a record in Employee, which I mean
I have to code this.
Am I doing something wrong in my code or is it simply that it is not
[yet] implemented in Rails ?
thanks in advance.