Author Topic: ShipmentItem - Why not have it be related to Shipment using 1:n relationship  (Read 4020 times)


  • Newbie
  • *
  • Posts: 1
    • View Profile
Chapter 12: Working with Core Data

The design uses a shipmentID in ShipmentItem to link to a Shipment.  Why not just use an explicit relationship here of 1 to many from Shipment to ShipmentItem?

Are there problems with the relationship approach and using business objects that I have not thought about?




  • Administrator
  • *****
  • Posts: 719
    • View Profile

Good question. My main reason for not using a relationship was to show how to work with entities that don't have an explicit relationship defined in the entity data model.

As mentioned in the section "The Downside of Relationships", all entities in a relationship must be retrieved from a single object context (if you plan on updating them later on)! As it mentions in that section:

" if you take this principle to the extreme and create relationships between all entities in your entity data model, then all types of entities must be retrieved from the same object context. Then, when you save changes to one type of entity and tell the object context to perform a save, it automatically saves changes to all entities. You lose the ability to update one type of entity at a time."