Imagine the scenario:
I have a class with different types of students. All students have similar attributes, but each type of student has also unique atributes. So I used MTI to keep the common attributes in the table students and the individual ones in their respective table, and polimorphism to abstract the student type when handling them from the class perspective. I followed this tutorial: http://techspry.com/ruby_and_rails/multiple-table-inheritance-in-rails-3/.
From this, I got to these models:
class Clazz < ActiveRecord::Base
has_many :students
end
class Student < ActiveRecord::Base
belongs_to :stu, :polymorphic => true
belongs_to :clazz
end
class Student1 < ActiveRecord::Base
has_one :student, :as => :stu
end
class Student2 < ActiveRecord::Base
has_one :student, :as => :stu
end
My problem comes when I want to instantiate a specific student (indirectly associated to the class through student). I can't do it from the class, because it doesn't have a connection to the specific students and when I try to instantiate it directly, it says it doesn't recognize the ':class' field.
Student1.new(:clazz => @clazz, ... [other atributes]...)
unknown attribute: :class
Can anyone give me a hint on how to accomplish this? Tks