Search code examples
ruby-on-railsormhas-many-throughhas-many-polymorphs

Rails 2: has_many :through validation?


Rails 2.1.0 (Cannot upgrade for now due to several constraints) I am trying to achieve this. Any hints?

  1. A project has many users through join model
  2. A user has many projects through join model
  3. Admin class inherits User class. It also has some Admin specific stuff.
  4. Admin like inheritance for Supervisor and Operator
  5. Project has one Admin, One supervisor and many operators.

Now I want to 1. submit data for project, admin, supervisor and operator in a single project form 2. validate all and show errors on the project form.

Project has_many :projects_users ; has_many :users, :through => :projects_users
User has_many :projects_users ; has_many :projects, :through => :projects_users
ProjectsUser = :id integer, :user_id :integer, :project_id :integer
ProjectUser belongs_to :project, belongs_to :user
Admin < User # User has 'type:string' column for STI
Supervisor < User
Operator < User

Is the approach correct? Any and all suggestions are welcome.


Solution

  • I ended up using virtual attributes for admin, supervisor and operators everything else went through ORM associations