title: Multiple entries in a :has_many through association
body: <p>I need some help with a rails development that I'm working on, using rails 3.
  This app was given to me a few months ago just after it's inception and I have since become rather fond of Ruby.</p>
  
  <p>I have a set of Projects that can have resources assigned through a teams table.</p>
  
  <p>A team record has a start date and a end date(i.e. when a resource was assigned and de-assigned from the project).</p>
  
  <p>If a user has been assigned and deassigned from a project and at a later date they are to be assigned back onto the project, 
  instead of over writting the end date, I want to create a new entry in the Teams table, to be able to keep a track of the dates that a resource was assigned to a certain project.</p>
  
  <p>So my question is, is it possible to have multiple entries in a :has_many through association?</p>
  
  <p>Here's my associations:</p>
  
  <pre><code>class Resource &lt; ActiveRecord::Base
    has_many :teams
    has_many :projects, :through =&gt; :teams 
  end
  
  class Project &lt; ActiveRecord::Base
    has_many :teams
    has_many :resources, :through =&gt; :teams
  end
  
  class Team &lt; ActiveRecord::Base
    belongs_to :project
    belongs_to :resource
  end
  </code></pre>
  
  <p>I also have the following function in Project.rb:</p>
  
  <pre><code>after_save  :update_team_and_job
  
  private
    def update_team_and_job
  
      # self.member_ids is the selected resource ids for a project
  
      if self.member_ids.blank?
        self.teams.each do |team|
          unless team.deassociated
            team.deassociated = Week.current.id + 1
            team.save
          end
        end
      else
        self.teams.each do |team|
  
          #assigning/re-assigning a resource
  
          if self.member_ids.include?(team.resource_id.to_s)
            if team.deassociated != nil
              team.deassociated = nil
              team.save
            end
          else
  
            #de-assigning a resource
  
            if team.deassociated == nil
              team.deassociated = Week.current.id + 1
              team.save
            end
          end
        end
  
        y = self.member_ids - self.resource_ids
        self.resource_ids = self.resource_ids.concat(y)
  
        self.member_ids = nil
      end
    end
  end
  </code></pre>