iphone - Core Data modeling of relationships -
i'm modeling app in core data. have object called 'stats' have 'player', 'team', , 'game' associated each object. once these stats objects stored, imagine querying them 1 or more of these attributes (player, team, game). see model below.
question 1: make sense model these 'relationships' opposed 'attributes'.
question 2: when retrieving form nspredicates using objects , not have keep track of unique ids names each player, team, or game. if store player, team, , game objects (as opposed unique ids or names) each entity, best way retrieve them. following work if wanted retrieve stats objects particular 'team' (someteamobject) or need query objectid?
nspredicate *predicate = [nspredicate predicatewithformat:@"team == %@", someteamobject];
thanks
if understand question right, yes, makes sense model these separate objects relationships between them. when fetching various objects; could, example, single player associated given stat, or stats game. leads second question:
instead of using predicate, note relationships have names; instead of building full nsfetchrequest associated nspredicate, call relevant accessor method. request stat objects team, call
[team stats]
, nsarray of stat objects.
Comments
Post a Comment