0

[A]<<------------->[B].attribute

Can't fetch / sort objects based on the attribute by relationship if the object by the relationship is inherited from the abstract class

NSSortDescriptor *titleSort = [[NSSortDescriptor alloc]initWithKey:@"b.attribute" ascending:YES];
[fetchRequest setSortDescriptors:@[titleSort]]; 


Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'keypath b.attribute not found in entity <NSSQLEntity A id=17>'

So we have the "to-one" relationship to the [B] wich has some an attribute;

When i try to fetch [A] by "attribute" of [B] i have a crash.

It's is very strange and seems Core Data doesn't support dealing with keypath which use an inherited entities

Have you ever met this????

The same for a predicate - please help !!!

Ask questions, all what you want

5
  • Is the relationship not possibly B instead of b making it 'B.attribute'
    – sbarow
    Dec 4, 2013 at 12:13
  • sorry, what do you mean? Dec 4, 2013 at 12:19
  • In your example you state [A]<<-->>[B].attribute but in your sort descriptor you use b.attribute it should in fact be B.attribute if this is not just pseudo code.
    – sbarow
    Dec 4, 2013 at 12:22
  • Yes it's just pseudo code. I have made it to simplify the situation. In fact under the "b.attribute" i have "mainEntity.date" keypath in my code Dec 4, 2013 at 12:26
  • It's is very strange and seems Core Data doesn't support dealing with keypath which use an inherited entities Dec 4, 2013 at 12:28

1 Answer 1

-1

I'm not sure the problem is that B is an inherited entity. Usually you can't do operation at the second level (on an attribute on another entity B related to entity A).

Basically you should do it in two steps:

  1. Retrieve all the B objects, sorted by attribute
  2. Get the A objects from the B objects (really easy because you have a 1-to-1 relationship) with a for-each loop

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.