On 28 September 2011 20:28, ERB <[email protected]> wrote:
> I have two models, users and companies as indicated below.  The users
> table has a foreign_key "company_id".
>
> class User < ActiveRecord::Base
>     has_many :companies
> end
>
> class Company < ActiveRecord::Base
>    belongs_to: user
> end

If you user has many companies, then Company needs the foreign key
user_id to belong to user.
Change your DB schema; remove the company_id field from users and add
the field to companies.

-- 
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 [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to