ios - NSPredicate filter inherited object in coredata -


question

hi all, here have designed coredata (i'll write simple possible, while real data more complex):

product (abstract)    - nsstring *productname    - nsdecimalnumber *productprice    - nsstring *producttype  productcomplex : product    - (nsset <productsimple *> *)childproducts  productsimple : product    - (productcomplex *)parentproduct 

so basically, product abstract type, has 2 properties: name , price. there 2 inheritances product:

  1. productcomplex: may have many child products.
  2. productsimple: may child of complex product or not.

then, have list display product (the abstract product, of course). want create predicate filter product list these conditions:

  1. only display productcomplex have childproducts (childproducts.@count > 0).
  2. only display productsimple doesn't have parentproduct (parentproduct = nil).

my try

i'm using nsfetchresultcontroller, entityname product. i've tried create predicate:

nspredicate *predicate = [nspredicate predicatewithformat:@"childproducts.@count > 0 or parentproduct = nil"]; 

this cause crash when perform fetching fetchresultcontroller:

if (![self.fetchedresultscontroller performfetch:&error]) {...}

this simplified crash reason:

*** terminating app due uncaught exception 'nsinvalidargumentexception', reason: 'can't have non-relationship collection element in subquerysubquery(childproducts, $child, $child.productprice > "0")'

please me create filter those.

edit 1

i've tried predicate below make sure has relationship, doesn't work also.

[nspredicate predicatewithformat:@"producttype = 'complex' , childproducts.@count > 0"]

edit 2

after turn on sql debug mode, i've found sql fetch generated out. read sql query, think it's impossible ask :( still hope answer that.


Comments

Popular posts from this blog

Spring Boot + JPA + Hibernate: Unable to locate persister -

go - Golang: panic: runtime error: invalid memory address or nil pointer dereference using bufio.Scanner -

c - double free or corruption (fasttop) -