title: Rails "magic" joins not working - activerecord not finding linked table entries
body: <p>I have two models in my app, CompanyUk, and CompanyName. CompanyUk hasmany CompanyNames. Activerecord is creating CompanyUk.CompanyNames, but it won't find any CompanyNames. Here's the code:</p>
  
  <pre><code>class CompanyName &lt; ActiveRecord::Base
    belongs_to :CompanyUk, :foreign_key =&gt; "company_number"
  end
  
  class CompanyUk &lt; ActiveRecord::Base
  
    has_many :CompanyNames, :dependent =&gt; :destroy, :foreign_key =&gt; "company_number"
  
    validates_presence_of :company_number, :reg_office, :type, :incorporation_date #, :next_accounts_date, :next_return_date # should eventually have these
  
    validates_uniqueness_of :company_number, :case_sensitive =&gt; false
  
    validates_associated :CompanyNames
  
    set_inheritance_column :kind
  end
  
  class CreateCompanyUks &lt; ActiveRecord::Migration
    def self.up
      create_table :company_uks do |t|
        t.string :company_number, :null=&gt;false
        t.text :reg_office, :null=&gt;false
        t.string :type, :null=&gt;false
        t.string :business_nature
        t.string :status
        t.date :incorporation_date, :null=&gt;false
        t.date :last_accounts_date
        t.date :next_accounts_date
        t.date :last_return_date
        t.date :next_return_date
  
        t.primary_key :company_number
  
        t.timestamps
      end
    end
  end
  
  
  
  class CreateCompanyNames &lt; ActiveRecord::Migration
    def self.up
      create_table :company_names do |t|
        t.string :company_number, :null=&gt;false
        t.string :name, :null=&gt;false
        t.date :date_adopted, :null=&gt;false
  
        t.timestamps
      end
    end
  end
  </code></pre>
  
  <p>The contents of the database:</p>
  
  <pre><code>irb(main):011:0&gt; CompanyUk.all
  =&gt; [#&lt;CompanyUk id: 1, company_number: "12345", reg_office: "Example office", type: "Private company limited by shares", business_nature: nil, status: nil, incorporation_date: "2011-05-28", last_accounts_date: nil, next_accounts_date: nil, last_return_date: nil, next_return_date: nil, created_at: "2011-05-28 09:47:19", updated_at: "2011-05-28 09:47:19"&gt;]
  
  irb(main):012:0&gt; CompanyName.all
  =&gt; [#&lt;CompanyName id: 1, company_number: "12345", name: "foo ltd", date_adopted: "2011-05-28", created_at: "2011-05-28 09:47:19", updated_at: "2011-05-28 09:47:19"&gt;, #&lt;CompanyName id: 2, company_number: "12345", name: "foo ltd", date_adopted: "2011-05-28", created_at: "2011-05-28 10:09:29", updated_at: "2011-05-28 10:09:29"&gt;, #&lt;CompanyName id: 3, company_num
  ber: "1", name: "foobar ltd", date_adopted: "2011-05-28", created_at: "2011-05-28 0:10:52", updated_at: "2011-05-28 10:10:52"&gt;]
  </code></pre>
  
  <p>Despite there being multiple CompanyNames: </p>
  
  <pre><code>irb(main):009:0&gt; CompanyUk.all.first.CompanyNames
  =&gt; []
  </code></pre>
  
  <p>In addition, creating a new CompanyName through CompanyUk.CompanyNames doesn't set the CompanyNumber (the primary key for CompanyUk, and the foreign key set on the relations) correctly.</p>
  
  <p>So, is there any way to fix this? Or even better a good reference for how models and associations work?</p>