在实体 <NSSQLEntity Theaters id=3> 中找不到 coredata keypath nameOfMovie
coredata keypath 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];
但是我收到这个错误:
keypath nameOfMovie not found in entity <NSSQLEntity Theaters id=3>
我也试过了:
NSPredicate *theaterPredicate = [NSPredicate predicateWithFormat:@"nameOfTheater like %@ AND Movies.nameOfMovie like %@",_theaterName,_movieOutlet.stringValue];
但是我得到了这个错误:
keypath Movies.nameOfMovie not found in entity <NSSQLEntity Theaters id=3>
我也试过:
NSPredicate *theaterPredicate = [NSPredicate predicateWithFormat:@"nameOfTheater like %@ AND movies.nameOfMovie like %@",_theaterName,_movieOutlet.stringValue];
我收到以下错误:
此处不允许对多密钥
你们中的任何人都可能知道我做错了什么或我的代码中缺少什么。非常感谢你的帮助。
更新:
这是我的核心数据模型的头文件:
影院classe:
@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:
@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;
时间表class:
@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;
你可以用SUBQUERY
来解决这类问题
一个确切的剧院实体(由您的示例复制)
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"nameOfTheater like %@ AND SUBQUERY(movies, $mv, $mv.nameOfMovie like %@).@count > 0", _theaterName,_movieOutlet.stringValue];
更新
电影abc所在的所有影院运行
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SUBQUERY(movies, $mv, $mv.nameOfMovie CONTAINS[c] %@).@count > 0", @"abc"];
顺便说一句,你的模型正确吗?
Theaters <->> Movies = 1:n
所以每个 Theater
都有 x Movies
,但是 Movie
只有一个 Theater
是 运行
因此,如果您获取名称为 "abc" 的 Movie
,您可以获得 Theater
作为属性。或者是
Theaters <<->> Movies = n:m
?所以 movies
和 movieTheaters
是 NSSet<Movie>/NSSet<Theater>
更新 2
上面的问题还需要一个答案。之间的正确关系是什么?是 x 家影院或仅一家影院的一部电影。 ManagedObject 类 的头文件如何? ;)
NSEntityDescription *schedulesDescription = [NSEntityDescription entityForName:@"Schedules" inManagedObjectContext:moc];
// something like this if 1:n. Try and post logs, have no IDE at the moment
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"movie.nameOfMovie == %@ AND movie.movieTheaters.nameOfTheater == %@", @"movie8", @"theaterOne"];
// if n:m, as far as I remember you couldn't fetch over 2 n:m relations via .
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"movie.nameOfMovie == %@ AND SUBQUERY(movie, $mv, $mv.movieTheaters.nameOfTheater == %@).@count > 0", @"movie8", @"theaterOne"];
我有一个 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];
但是我收到这个错误:
keypath nameOfMovie not found in entity <NSSQLEntity Theaters id=3>
我也试过了:
NSPredicate *theaterPredicate = [NSPredicate predicateWithFormat:@"nameOfTheater like %@ AND Movies.nameOfMovie like %@",_theaterName,_movieOutlet.stringValue];
但是我得到了这个错误:
keypath Movies.nameOfMovie not found in entity <NSSQLEntity Theaters id=3>
我也试过:
NSPredicate *theaterPredicate = [NSPredicate predicateWithFormat:@"nameOfTheater like %@ AND movies.nameOfMovie like %@",_theaterName,_movieOutlet.stringValue];
我收到以下错误:
此处不允许对多密钥
你们中的任何人都可能知道我做错了什么或我的代码中缺少什么。非常感谢你的帮助。
更新:
这是我的核心数据模型的头文件:
影院classe:
@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:
@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;
时间表class:
@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;
你可以用SUBQUERY
来解决这类问题
一个确切的剧院实体(由您的示例复制)
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"nameOfTheater like %@ AND SUBQUERY(movies, $mv, $mv.nameOfMovie like %@).@count > 0", _theaterName,_movieOutlet.stringValue];
更新
电影abc所在的所有影院运行
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SUBQUERY(movies, $mv, $mv.nameOfMovie CONTAINS[c] %@).@count > 0", @"abc"];
顺便说一句,你的模型正确吗?
Theaters <->> Movies = 1:n
所以每个 Theater
都有 x Movies
,但是 Movie
只有一个 Theater
是 运行
因此,如果您获取名称为 "abc" 的 Movie
,您可以获得 Theater
作为属性。或者是
Theaters <<->> Movies = n:m
?所以 movies
和 movieTheaters
是 NSSet<Movie>/NSSet<Theater>
更新 2
上面的问题还需要一个答案。之间的正确关系是什么?是 x 家影院或仅一家影院的一部电影。 ManagedObject 类 的头文件如何? ;)
NSEntityDescription *schedulesDescription = [NSEntityDescription entityForName:@"Schedules" inManagedObjectContext:moc];
// something like this if 1:n. Try and post logs, have no IDE at the moment
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"movie.nameOfMovie == %@ AND movie.movieTheaters.nameOfTheater == %@", @"movie8", @"theaterOne"];
// if n:m, as far as I remember you couldn't fetch over 2 n:m relations via .
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"movie.nameOfMovie == %@ AND SUBQUERY(movie, $mv, $mv.movieTheaters.nameOfTheater == %@).@count > 0", @"movie8", @"theaterOne"];