Skip to content

Instantly share code, notes, and snippets.

@jonhoman
Created December 22, 2010 02:17

Revisions

  1. jonhoman renamed this gist Dec 22, 2010. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  2. jonhoman created this gist Dec 22, 2010.
    20 changes: 20 additions & 0 deletions Rails Association Building
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,20 @@
    class Company < ActiveRecord::Base
    has_many :employees
    end

    class Employee < ActiveRecord::Base
    has_one :position
    belongs_to :company
    end

    class Position < ActiveRecord::Base
    belongs_to :employee
    end

    =======================================
    # time to build mulit-model form

    company.employees.build
    employee.build_position

    # why the inconsistent API???