views:

35

answers:

2

Hello,

I've been playing around with Active Record a bit, and I have noticed that A.C./ORM always uses the following database model when creating a one-to-one relationship

Person

id | country_id | name | ...

Country

id | tld | name | ...

No I wondered, isn't this a violiation of the third Normal Form? This clearly states "Every non-prime attribute is non-transitively dependent on every key of the table". Well this country_id isn't dependent of personid is it?

So is this wrong or am I just not getting the point?

+2  A: 

A functional dependency, A => B, means that each distinct value of A can, by definition, only be associated with a single value of B. In other words, if you know A, then B is a given. In this case, a given personid can only be associated with one country_id, therefore personid => country_id.

Marcelo Cantos
aah, okay, thanks!
Arsenal
+1 - country_id only records the country the person belongs to, so it is an attribute of the person (person lives in country). If the person record had 'region' as well (region is logically an attribute of the country) then it would violate 3NF.
ConcernedOfTunbridgeWells
+2  A: 

Yes, it is dependant.

In relational algebra, every table has a predicate associated with it (that is the statement that filled with values from table make a true fact).

So, for example "Person identified by id, comes from country country, has a name name, etc..."

The 3rd normal form is also sometimes phrased as: "Every non-prime attribute must provide a fact about the key, the whole key, and nothing but the key."

Which is to say that you are looking for transitive dependencies. An example of this would be

Person (id, country_id, tld, name, ...)

In this example tld is transitively dependant id, because it is dependant on country_id, which is dependant on id. So, this example would violate 3NF.

Unreason