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:
productcomplex
: may have many child products.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:
- only display
productcomplex
havechildproducts
(childproducts.@count > 0
). - only display
productsimple
doesn't haveparentproduct
(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
Post a Comment