Andy Tolle wrote in post #991031:
> For example:
> Currently I have:
> functions < functions_competencies < competencies
> exams      < exam_competencies      < competencies
>
> I'd like to dry up "functions_competencies" and "exam_competencies" by
> using a polymorphic association, by let's say 'attached_competencies':
>
> functions      < attached_competencies < competencies
> exams          < attached_competencies < competencies
> evaluations < attached_competencies < competencies
> ...
>
> Note that these are join tables.
>
> Is this possible?
IIRC, this is based on the has_many_polymorphs plugin

class appl
  has_many :appllinks
  has_many :projects,
           :through => :appllinks,
           :source => :project,
           :conditions =>? "appllinks.appllinkable_type = 'Project'"
  has_many :scenarios,
           :through => :appllinks,
           :source => :scenario,
           :conditions =>? "appllinks.appllinkable_type = 'Scenario'"
  has_many :unittests,
           :through => :appllinks,
           :source => :unittest,
           :conditions =>? "appllinks.appllinkable_type = 'Unittest'"

class appllink
  belongs_to :appl
  belongs_to :appllinkable, :polymorphic => true
  belongs_to :project,
             :class_name => 'Project',
             :foreign_key => 'appllinkable_id'
  belongs_to :scenario,
             :class_name => 'Scenario',
             :foreign_key => 'appllinkable_id'
  belongs_to :unittest,
             :class_name => 'Unittest',
             :foreign_key => 'appllinkable_id'

class project
  has_many :appllinks, :as => :applinkable, :dependent => :destroy
  has_many :appls, :through => :appllinks

classes scenario and unittest are just like project

YMMV

-- 
Posted via http://www.ruby-forum.com/.

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to