title: rails problem with multi model not working
body: <p>I'm trying to process the dsc files from an ubuntu's sourcecode repository to populate a rails application, for this I used 3 models:</p>
  
  <pre><code>class Architecture &lt; ActiveRecord::Base
    has_many :srcpkgs, :dependent =&gt; :destroy
    has_many :binpkgs, :through =&gt; :srcpkgs, :dependent =&gt; :destroy
  
    accepts_nested_attributes_for :srcpkgs, :allow_destroy =&gt; true
    accepts_nested_attributes_for :binpkgs, :allow_destroy =&gt; true
    validates_presence_of :name
    validates_uniqueness_of :name
  end
  
  class Srcpkg &lt; ActiveRecord::Base
    has_many :binpkgs, :dependent =&gt; :delete_all
    belongs_to :architecture
  
    accepts_nested_attributes_for :binpkgs
    attr_accessor :architecture_id, :bdeps
    validates_presence_of :architecture_id
  end
  
  class Binpkg &lt; ActiveRecord::Base
    belongs_to :srcpkg, :touch =&gt; true
    belongs_to :architecture
  
    accepts_nested_attributes_for :srcpkg
    accepts_nested_attributes_for :architecture
    attr_accessor :architecture_id, :srcpkg_id
    validates :architecture_id, :presence =&gt; true
  end
  </code></pre>
  
  <p>and using a controller admin with:</p>
  
  <pre><code>def populate
    notice = nil
    pname = '/tmp/dpkg_1.15.5.6ubuntu4.5.dsc'
    p = Pkg.new pname
    binpkg = []
    bdep = []
    if not Srcpkg.find_by_name(p.source.to_s)
      arch = Architecture.find_or_create_by_name(p.architecture.to_s)
      arch.save
      srcpkg = Srcpkg.find_or_initialize_by_name(p.source.to_s)
      p.bdepends.each do |b|
        b1 = Binpkg.find_or_initialize_by_name(b)
        b1.save
        bdep.push(b1.id)
      end
      srcpkg.update_attributes({:name =&gt; p.source.to_s,
                             :version =&gt; p.version.to_s,
                             :stdversion =&gt; p.stdversion.to_s,
                             :bdeps =&gt; bdep,
                             :arquitecture_id =&gt; arch.id})
      srcpkg.save
      p.binary.each do |b|
        b1 = Binpkg.create
        b1.name = b
        b1.srcpkg_id = srcpkg.id
        b1.arquitecture_id = arch.id
        b1.save
      end
      notice = "Package successfully processed"
      logger.debug " ---- here #2 ---- "
    else
      logger.debug " ---- here #3 ---- "
      notice = "Package not processed, it was already added"
    end
    flash[:notice] = notice
    redirect_to "/architectures/#{arch.id}"
  end
  </code></pre>
  
  <p>this doesn't create neither the srcpkg object, nor the binspkgs objects
  before this, I also tried this:</p>
  
  <pre><code>p = Pkg.new pname
  params = { :architecture =&gt; {
      :name =&gt; p.architecture.to_s,
      :srcpkgs_attributes =&gt; [{
          :name =&gt; p.source.to_s,
          :version =&gt; p.version.to_s,
          :stdversion =&gt; p.stdversion.to_s,
          :bdeps =&gt; [],
          :binpkgs_attributes =&gt; []
      }]
    }
  }
  p.binary.each do |b|
    params[:architecture][:srcpkgs_attributes][0][:binpkgs_attributes] &lt;&lt; {:name =&gt; b.to_s}
  end
  if not Srcpkg.find_by_name(p.source.to_s)
    arch = Architecture.find_or_create_by_name(p.architecture.to_s)
    arch.update_attributes(params[:architecture])
  </code></pre>
  
  <p>even with:</p>
  
  <pre><code>src = Srcpkg.new(params[:architecture][:srcpkgs_attributes][0])
  src.save
  </code></pre>
  
  <p>I searched for than a week now and tried other methods.. but no one worked.. so, any idea?
  thanks a lot</p>