簡體   English   中英

CoreData:獲取父級的子級

[英]CoreData: Fetching Children of Parent

我有一個CoreData模型,其父模型包含許多一對多的關系。 只有一個MenuList,但是每個子菜單都包含許多條目。

MenuList
-------
WineMenu (one-to many relationship)
BeerMenu (one-to many relationship)
FoodMenu (one-to many relationship)

是否可以直接從父級訪問子級菜單?

我正在獲得像這樣的MenuList:

NSArray *theMenuList = [managedObjectContext executeFetchRequest:fetchRequest error:&error]; 

MenuList中只有一個對象。 我無法執行此操作:

theMenuList.wineMenu.wineName

好吧,如果您確定數據庫中始終只有一個MenuList實例,則可以簡單地從返回的數組中獲取一個對象並使用它。

NSArray *menuLists = [managedObjectContext executeFetchRequest:fetchRequest error:&error];
MenuList *theMenuList = [menuLists lastObject];
NSLog(@"Wine name: %@", theMenuList.wineMenu.wineName);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM