• 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
Re: Aggregations in a DAG with a Recursive Core Data Structure
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Aggregations in a DAG with a Recursive Core Data Structure


  • Subject: Re: Aggregations in a DAG with a Recursive Core Data Structure
  • From: "Marcus S. Zarra" <email@hidden>
  • Date: Wed, 11 Jul 2007 09:56:10 -0600

Basically there are two ways to do this. Dynamically calculate this cost and storing it.

Dynamic is the easiest because you just extend NSManagedObject, add the accessors and do the calculation is code. Whenever someone asks for the cost you recalculate it. The bad side of this is that it gets slow very soon in a large data set.

The second option is to have a cost attribute in your core data repository. Whenever a child object changes a value (in your example cost), it calls to its parent and tells the parent to recalculate its own cost (which would then call its parent, etc.). This method is harder to get perfect in code but has the benefit of being significantly faster in larger data sets.

There might be a way to do this with some very fancy Key-Value Coding but to be honest you are much better off storing this derived value in the repository.

There is currently no way to do this as part of a fetch from the repository.

Marcus S. Zarra
Zarra Studios LLC
Simply Elegant Software for OS X
www.zarrastudios.com

On Jul 11, 2007, at 9:19 AM, Mike Rossetti wrote:

I'm sure this has been asked and answered before but a search of cocoa-dev using a wide variety of terms failed to come up with anything useful.

Imagine a basic parts list model with two entities:

	item
		name
		parts (1::n to part)
		totalCost

	part
		name
		subparts (1::n to part)
		cost

I'd like totalCost to be calculated from the sum of the item's parts costs. And I'd like each part's cost to be calculated as the sum of it's subparts' costs. The parts hierarchy can be arbitrarily deep. Cycles are not allowed.

Is there an example that shows how to implement the totalCost and cost fields? Preferably using Core Data.

Thanks,
Mike

_______________________________________________

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:
40zarrastudios.com


This email sent to email@hidden

Attachment: smime.p7s
Description: S/MIME cryptographic signature

_______________________________________________

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

References: 
 >Aggregations in a DAG with a Recursive Core Data Structure (From: Mike Rossetti <email@hidden>)

  • Prev by Date: Re: Finding windows made in Interface Builder?
  • Next by Date: Re: Finding windows made in Interface Builder?
  • Previous by thread: Aggregations in a DAG with a Recursive Core Data Structure
  • Next by thread: Tracking the amount of inbound/outbound network traffic
  • Index(es):
    • Date
    • Thread