• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Core Data + Unidirectional Relationships
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Core Data + Unidirectional Relationships


  • Subject: Core Data + Unidirectional Relationships
  • From: John Pannell <email@hidden>
  • Date: Wed, 12 Nov 2008 06:38:16 -0700

Hi all-

Looking for advice on the following scenario: consider an object graph made up of entities called "stations" (i.e. like subway stations all over town). Each station has two or more "port" entities (i.e. the openings in and out of the station), which each have one or more "pipe" entities (i.e. the tunnels that connect the stations to one another). A single port might have more than one pipe in the case that there is a fork in the tunnel, and a train exiting the port could end up in one of a variety of stations.

The station has a to-many "ports" relationship with a cascade delete rule, and the port has a to-one "station" relationship with a cascade delete rule - these are inverses on one another. So now, if I delete a station, all of its ports will also be deleted from the object graph. Deleting a port, on the other hand, will remove it from the ports relationship on the station, but leave the station otherwise intact.

My trouble comes in relating the ports and the pipes. I'd like to model the pipe by having a to-one "sourcePort" relationship (to represent the port at the start of the tunnel - note: all of my tunnels are one-way) and a to-one "targetPort" relationship to represent the port at the end of the tunnel. A port would have a to- many relationship with pipe as the target entity. The difficulty comes in specifying an inverse... for the port's "pipes" relationship, I'm forced to choose from either the sourcePort or the targetPort as the inverse, and for the pipe's sourcePort or targetPort relationships, setting either to port's "pipes" breaks the inverse setting of the other.

I can model this many-to-many between ports and pipes with some cardinality rules for the pipe (only two ports for a pipe), but then it feels like I'm doing extra work in code by having to determine which of a pipe's ports is the sourcePort, and which is the targetPort. Alternately, I could leave the relationships unidirectional and be sure to delete attached pipes when deleting a port, and remove attached pipes from port's pipes set when deleting a pipe.

The core data documentation speaks strongly against unidirectional relationships... can anyone suggest better modeling for this scenario? Or testify to the soundness of unidirectional relationships if managed as described? Any help is appreciated!

John


John Pannell Positive Spin Media http://www.positivespinmedia.com _______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: Core Data + Unidirectional Relationships
      • From: Alexander Spohr <email@hidden>
    • Re: Core Data + Unidirectional Relationships
      • From: Keary Suska <email@hidden>
  • Prev by Date: Re: Drag Tabs, Custom Colors
  • Next by Date: Cora Animation transormation
  • Previous by thread: Re: NSImage in NSAttributedString
  • Next by thread: Re: Core Data + Unidirectional Relationships
  • Index(es):
    • Date
    • Thread