且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

coredata keypath nameOfMovie在实体中找不到< NSSQLEntity Theaters id = 3>

更新时间:2023-11-18 15:28:28

可以使用 SUBQUERY 这种问题

一个确切的剧院实体(由您的示例复制)

one exact theater entity (copied by your example)

NSPredicate *predicate = [NSPredicate predicateWithFormat:@"nameOfTheater like %@ AND SUBQUERY(movies, $mv, $mv.nameOfMovie like %@).@count > 0", _theaterName,_movieOutlet.stringValue];

UPDATE

所有影院运行电影abc

all theaters where movie abc is running

NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SUBQUERY(movies, $mv, $mv.nameOfMovie CONTAINS[c] %@).@count > 0", @"abc"];

btw,您的模型是否正确?

btw, is you model correct?

Theaters <->> Movies = 1:n

电影,但电影只在一​​个剧院
因此,如果您以名称abc获取 Movie ,您可以获得 Theater 。或者

So every Theater has x Movies, but a Movie is running in only one Theater So if you fetch a Movie with name "abc" you can get the Theater as attibute. Or is it

Theaters <<->> Movies = n:m

?因此电影 movieTheaters NSSet< Movie> / NSSet< Theater>

UPDATE 2

仍然需要回答上述问题。什么是正确的关系?是一个电影在x影院或只在一个。你的头文件是如何为ManagedObject类? ;)

still need an answer for the question above. what is the correct relation between? is one movie in x theaters or only in one. how are your header files for the ManagedObject classes? ;)

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"];