Re: Model relationship design question.

Andrew Skegg
2008-05-15T01:25:31Z

maestro777 wrote:
> Thanks Ryan for your input.
> I thought over you have suggested, and I think it doesn''t quite
work
> for the case that I have.
>
> Let me try to explain my scenario again.
>
> I have a table of companies.

OK

class Company < ActiveRecord::Base
end

>Each company has multiple users.

class Company < ActiveRecord::Base
  has_many :users
end

class User < ActiveRecord::Base
  belong_to :company
end

> Each user can submit one or more articles.

class Article < ActiveRecord::Base
  belongs_to :user
end

class Company < ActiveRecord::Base
  has_many :users
end

class User < ActiveRecord::Base
  belong_to :company
  has_many :articles
end

> Each article is about a company (that exists in the company table) and
> that company may or may not be the same company that the user
> (submitting the article) belongs to.

class Article < ActiveRecord::Base
  belongs_to :user
  belongs_to :company
end

class Company < ActiveRecord::Base
  has_many :users
  has_many :articles
end

class User < ActiveRecord::Base
  belong_to :company
  has_many :articles
end


I am not sure you need :through relationships at all.
--
Posted via http://www.ruby-forum.com/.