Re: Model relationship design question.

Carsten Gehling
2008-05-15T20:39:57Z

Andrew Skegg wrote:

>> 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.
...

+1 to Andrew''s suggestion. And let me explain why i think you are
confused:

Your original suggestion mirrors that of Andrew. I''ve drawn it up in a
diagram:

Company 1---n User    (Relation1)

User 1----n Article   (Relation2)

Company 1---n Article (Relation3)

The confusion might come because you think, that this design implies
this rule:

Company CA has a user U1

U1 writes the article Ai

Then you automatically believe, that company CA is related to the
article Ai.

And it is, but can actually be related in TWO different was:

Company CA "owns" (has authored) article Ai (through Relation1 &
Relation2)

but at the same article Ai can relate to company CA (as the article''s
subject) or relate to an entirely different company - through Relation3.

Sometimes (probably a lot of the times) the owner of the article and the
subject of the article will be the same company. Therefore you believe,
that this relation structure is redundant. It is. But at the same time
it is a "necessary evil" to accomplice what you want.

I hope this clarifies some things. Your relation structure is sound, but
you probably didn''t know why. :-)

- Carsten
--
Posted via http://www.ruby-forum.com/.