Ios 在实体中找不到移动的coredata密钥路径名称<;NSSQLEntity影院id=3>;
我有一个coredata项目,我正在尝试进行查询。以下是我的coredata模型:Ios 在实体中找不到移动的coredata密钥路径名称<;NSSQLEntity影院id=3>;,ios,iphone,cocoa,core-data,Ios,Iphone,Cocoa,Core Data,我有一个coredata项目,我正在尝试进行查询。以下是我的coredata模型: NSManagedObjectContext *moc = [self managedObjectContext]; NSEntityDescription *theaterDescription = [ NSEntityDescription entityForName:@"Theaters" inManagedObjectContext:moc]; NSPredicate *theater
NSManagedObjectContext *moc = [self managedObjectContext];
NSEntityDescription *theaterDescription = [ NSEntityDescription entityForName:@"Theaters" inManagedObjectContext:moc];
NSPredicate *theaterPredicate = [NSPredicate predicateWithFormat:@"nameOfTheater like %@ AND nameOfMovie like %@",_theaterName,_movieOutlet.stringValue];
NSFetchRequest *theaterRequestTwo = [NSFetchRequest new];
theaterRequestTwo.entity = theaterDescription;
theaterRequestTwo.predicate = theaterPredicate;
NSError *error = nil;
NSArray *theaterResults = [moc executeFetchRequest:theaterRequestTwo error:&error];
但我得到了一个错误:
keypath nameOfMovie not found in entity <NSSQLEntity Theaters id=3>
keypath Movies.nameOfMovie not found in entity <NSSQLEntity Theaters id=3>
但我有一个错误:
keypath nameOfMovie not found in entity <NSSQLEntity Theaters id=3>
keypath Movies.nameOfMovie not found in entity <NSSQLEntity Theaters id=3>
我得到了以下错误:
这里不允许使用多个键
你们中的任何人都可能知道我做错了什么,或者我的代码遗漏了什么。我非常感谢你的帮助
更新:
以下是我的coredata模型的标题文件:
NSManagedObjectContext *moc = [self managedObjectContext];
NSEntityDescription *theaterDescription = [ NSEntityDescription entityForName:@"Theaters" inManagedObjectContext:moc];
NSPredicate *theaterPredicate = [NSPredicate predicateWithFormat:@"nameOfTheater like %@ AND nameOfMovie like %@",_theaterName,_movieOutlet.stringValue];
NSFetchRequest *theaterRequestTwo = [NSFetchRequest new];
theaterRequestTwo.entity = theaterDescription;
theaterRequestTwo.predicate = theaterPredicate;
NSError *error = nil;
NSArray *theaterResults = [moc executeFetchRequest:theaterRequestTwo error:&error];
剧院等级:
@class Movies;
@interface Theaters : NSManagedObject
@property (nonatomic, retain) NSString * nameOfTheater;
@property (nonatomic, retain) NSSet *movies;
@end
@interface Theaters (CoreDataGeneratedAccessors)
- (void)addMoviesObject:(Movies *)value;
- (void)removeMoviesObject:(Movies *)value;
- (void)addMovies:(NSSet *)values;
- (void)removeMovies:(NSSet *)values;
电影类:
@class Schedules, Theaters;
@interface Movies : NSManagedObject
@property (nonatomic, retain) NSString * nameOfMovie;
@property (nonatomic, retain) NSSet *showTimes;
@property (nonatomic, retain) Theaters *theaters;
@end
@interface Movies (CoreDataGeneratedAccessors)
- (void)addShowTimesObject:(Schedules *)value;
- (void)removeShowTimesObject:(Schedules *)value;
- (void)addShowTimes:(NSSet *)values;
- (void)removeShowTimes:(NSSet *)values;
课程表:
@interface Schedules : NSManagedObject
@property (nonatomic, retain) NSDate * showTimes;
@property (nonatomic, retain) NSSet *movie;
@end
@interface Schedules (CoreDataGeneratedAccessors)
- (void)addMovieObject:(Movies *)value;
- (void)removeMovieObject:(Movies *)value;
- (void)addMovie:(NSSet *)values;
- (void)removeMovie:(NSSet *)values;
对于此类问题,可以使用
子查询
一个精确的剧院实体(根据您的示例复制)
更新
所有放映abc电影的影院
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SUBQUERY(movies, $mv, $mv.nameOfMovie CONTAINS[c] %@).@count > 0", @"abc"];
顺便问一下,你的型号正确吗
Theaters <->> Movies = 1:n
??所以电影
和电影加热器
是NSSet/NSSet
更新2
仍然需要回答上述问题。两者之间的正确关系是什么?一部电影在x影院上映还是只在一家影院上映。ManagedObject类的头文件如何处理?;)
对于此类问题,可以使用子查询
一个精确的剧院实体(根据您的示例复制)
更新
所有放映abc电影的影院
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SUBQUERY(movies, $mv, $mv.nameOfMovie CONTAINS[c] %@).@count > 0", @"abc"];
顺便问一下,你的型号正确吗
Theaters <->> Movies = 1:n
??所以电影
和电影加热器
是NSSet/NSSet
更新2
仍然需要回答上述问题。两者之间的正确关系是什么?一部电影在x影院上映还是只在一家影院上映。ManagedObject类的头文件如何处理?;)
最后一个解决方案似乎是一个很好的提示。你的问题在这里得到了解释:最后一个解决方案似乎是一个很好的提示。你的问题已经在那里解释了:谢谢你的回答,但我正在寻找确切的匹配。例如,我有电影院放映电影4。通过你的查询,我得到了剧院的名称和电影的序列。你知道我如何构建查询才能得到电影院匹配电影的名称吗?我可以做任何事,但请解释更多,我不能理解你^^你想要一个电影院实体还是一个所有电影院的阵列来运行电影?^如果是第二种情况,我将更新我的回答每家影院都有电影,我需要查询影院和电影的名称,以获得这对影院的所有详细信息。例如,如果名为“theaterOne”的影院正在播放名为“movie8”的电影,我查询该NSPredicate*谓词=[NSPredicate predicateWithFormat:@“类似于电影的名称%@和子查询(电影,$mv,$mv.nameOfMovie like%@)。@count>0”,@“theaterOne”,“movie8]”;您将始终获得在NSEntityDescription
中定义的实体类型。因此,如果要获取电影
,必须更改描述和谓词。我更新了我的答案,这样你们就可以看到时间表的获取看起来是怎样的。我想知道答案,但我正在寻找精确的匹配。例如,我有电影院放映电影4。通过你的查询,我得到了剧院的名称和电影的序列。你知道我如何构建查询才能得到电影院匹配电影的名称吗?我可以做任何事,但请解释更多,我不能理解你^^你想要一个电影院实体还是一个所有电影院的阵列来运行电影?^如果是第二种情况,我将更新我的回答每家影院都有电影,我需要查询影院和电影的名称,以获得这对影院的所有详细信息。例如,如果名为“theaterOne”的影院正在播放名为“movie8”的电影,我查询该NSPredicate*谓词=[NSPredicate predicateWithFormat:@“类似于电影的名称%@和子查询(电影,$mv,$mv.nameOfMovie like%@)。@count>0”,@“theaterOne”,“movie8]”;您将始终获得在NSEntityDescription
中定义的实体类型。因此,如果要获取电影
,必须更改描述和谓词。我更新了我的答案,以便您可以看到时间表的获取是什么样子的