我建立一個地圖應用有以下實體:'對多關鍵在這裏不允許'例外,但爲什麼?
協調,地圖是對一個地圖座標是一個一對多的關係。
而且我的代碼是:
fileprivate var fetchedResultsControllerForMapEntity: NSFetchedResultsController<Map> = {
// Create Fetch Request
let fetchRequest: NSFetchRequest<Map> = Map.fetchRequest()
// Configure Fetch Request
fetchRequest.sortDescriptors = [NSSortDescriptor(key: "name", ascending: true)]
fetchRequest.predicate = NSPredicate(format:"newRelationship == %@", "peachesfarm")
// Create Fetched Results Controller
let fetchedResultsControllerForMapEntity = NSFetchedResultsController(fetchRequest: fetchRequest, managedObjectContext: managedObjectContext, sectionNameKeyPath: nil, cacheName: nil)
return fetchedResultsControllerForMapEntity
}()
fileprivate var fetchedResultsControllerForCoordinateEntity: NSFetchedResultsController<Coordinate> = {
// Create Fetch Request
let fetchRequest: NSFetchRequest<Coordinate> = Coordinate.fetchRequest()
// Configure Fetch Request
fetchRequest.sortDescriptors = [NSSortDescriptor(key: "latitude", ascending: true)]
fetchRequest.sortDescriptors = [NSSortDescriptor(key: "longitude", ascending: true)]
// Create Fetched Results Controller
let fetchedResultsControllerForCoordinateEntity = NSFetchedResultsController(fetchRequest: fetchRequest, managedObjectContext: managedObjectContext, sectionNameKeyPath: nil, cacheName: nil)
return fetchedResultsControllerForCoordinateEntity
}()
我基本上是試圖檢索名爲「peachesfarm」只有地圖的座標。爲什麼我會得到這個異常?
' newRelationship'混淆不清,你應該命名關係'Map' - >'Coordinate' **座標**(表示 - >很多)和反向關係'Coordinate' - >'Map' ** map **(表示 - >一個)。然後創建'NSManagedObject'子類並使用屬性。 – vadian
好的,但是我的代碼/ db有什麼問題? – konyv12
要獲取具有給定名稱的地圖的所有座標,必須在「座標」和謂詞「map.name ==%@」(在您的術語中:「newRelationship.name =%@」)上創建一個提取請求,並且而不是相反。 –