当前位置: 动力学知识库 > 问答 > 编程问答 >

objective c - iPhone - Data fetching from Parent table using Child Object in core Data

问题描述:

I have two Data Base which is shown in the attacted picture

I have the NewRelease Object and i want to get it's parent Object which is Contract. Means i want to know that this NewRelease Object belong to which Contract. I am unable to fetch the data can any one guide be what should be a rite predicate for this situation. I am successfully fetching the data for it's inverse case in NewRelease and Signature Table using this predicate Line

NSArray *filterResults = [mutableFetchResults filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"hasNewReleases = %@",aNewRelease]];

where aNewRelease is my NewRelease Object now how can i fetch data from Contracts Table using NewRelease Object.

There is "One to Many" Relation between NewRelease and Contracts such that one single Contract can belong to multiple NewReleases. Npw as i have mention above i have newRelease Object and i want to know that this newRelease belong to which Contract.

网友答案:

Add relationship between NewRelease and Contract table , then whenever you will fetch data from NewRelease or Contract entity ,you can access the data with its associated relationship. Check the following example : http://www.raywenderlich.com/934/core-data-on-ios-5-tutorial-getting-started

网友答案:

you should add an attribute naming contracId in NewRelease. So that there is always an id of contract for each NewRelease object and hence you can easily fetch data for each new release using the contractID.

chill :)

分享给朋友:
您可能感兴趣的文章:
随机阅读: