Single-valued entity associations Let s change the mapping from a User to an Address. Instead of the shared primary key, you now add a SHIPPING_ADDRESS_ID column in the USERS table: The mapping element in XML for this association is not , as you might have expected. The reason is simple: You don t care what s on the target side of the association, so you can treat it like a to-one association without the many part. All you want is to express This entity has a property that is a reference to an instance of another entity and use a foreign key field to represent that relationship. The database schema for this mapping is shown in figure 7.3. Figure 7.3 A one-to-one foreign key association between USERS and ADDRESS An additional constraint enforces this relationship as a real one to one. By making the SHIPPING_ADDRESS_ID column unique, you declare that a particular address can be referenced by at most one user, as a shipping address. This isn t as strong as the guarantee from a shared primary key association, which allows a particular address to be referenced by at most one user, period. With several foreign key columns (let s say you also have unique HOME_ADDRESS_IDand BILLING_ADDRESS_ID), you can reference the same address target row several times. But in any case, two users can t share the same address for the same purpose. Let s make the association from User to Address bidirectional. Inverse property reference The last foreign key association was mapped from Userto Addresswith and a unique constraint to guarantee the desired multiplicity. What mapping
In case you need affordable webhost to host your website, our recommendation is ecommerce web host services.
This entry was posted
on Thursday, January 31st, 2008 at 9:12 pm and is filed under PHP5.
You can follow any responses to this entry through the RSS 2.0 feed.
You can leave a response, or trackback from your own site.