Forum: Ruby on Rails polymorphic associations ok in read but not in create...

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Romain E. (Guest)
on 2007-01-05 18:33
 Hi, I am trying to use polymorphic associations to solve the following
problem:
I want a general class 'Employee' which content can come from 2 other
classes.
The code is:

class Employee < ActiveRecord::Base
# :assignable is the interface we expose to mask of various employee
types.
belongs_to :assignable, :polymorphic => true
end

class User < ActiveRecord::Base
# polymorphic association
has_many :employees, :as => :assignable #here I am not sure if I should
put has_many or has_one ?
end

class Secretary < ActiveRecord::Base
# polymorphic association
has_many :employees, :as => :assignable
end

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.

Romain.
This topic is locked and can not be replied to.