> 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 rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
No comments:
Post a Comment