Note that there are some explanatory texts on larger screens.

plurals
  1. POCore Data: What should I use as a Sort Descriptor with ordered set (ios5) in a many to many relationship
    primarykey
    data
    text
    <p><img src="https://i.stack.imgur.com/bZEM1.png" alt="enter image description here">- I have an <code>Item</code> Entity and a <code>Tag</code> Entity. - Items can have multiple Tags and Tags can be linked to multiple Items (many to many relationship). - The relationship is an "Ordered Relationship" (using Ordered relationship in IOS5) both ways.</p> <p>I want to fetch all child tags for a given item</p> <p>Im using the following fetch request:</p> <pre><code>NSFetchRequest* request = [NSFetchRequest fetchRequestWithEntityName:@"Item"]; // Fetch all items that have a given tag Tag* myTag = ....; request.predicate = [NSPredicate predicateWithFormat:@"ANY tag == %@", myTag]; // This is my attempt to get the correct sort ordering (it crashes) NSSortDescriptor *sortDescriptor = [NSSortDescriptor sortDescriptorWithKey:@"tag" ascending:YES]; request.sortDescriptors = @[sortDescriptor]; </code></pre> <p>The above sort descriptor returns data (which I assume is in some order) but then crashes:</p> <pre><code>[_NSFaultingMutableOrderedSet compare:]: unrecognized selector sent to instance 0x10b058f0 *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[_NSFaultingMutableOrderedSet compare:]: unrecognised selector sent to instance 0x10b058f0' </code></pre> <p>If I give an empty sort descriptors array then I dont get a crash but the result is not ordered. </p> <p>How do I correctly implement the sort descriptor in a many to many relationship using the ordered relationship feature in ios5?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. COCan you clarify what Entity you are fetching instances of? If you're fetching instances of `Item`, then the sort descriptor is to determine the sort order of the `Item`s and has nothing to do with the ordered relationship `Item` has to `Tag`. The exception is caused because your keyPath doesn't end in an attribute but a set. Try `tags.@count` for example instead.
      singulars
    2. COI have a similar query. In this case, I am looking for all Items associated with Tag (fetch request on Item entity) and since Tag to Item is an ordered relationship, I want to fetch Items linked with Tags "in the order" it was saved in the database. Coredata does not expose the intermediate table used for maintaining the ordered relationship, so how to specify that in the NSFetchedResultsController?
      singulars
    3. COI am trying to fetch all instances of Items linked to a Tag intance in the order it was saved. I am printing out the sql query to the console and if i use tags as the sort descriptor, i can see the result is ordered by an intermediate table , however this is internal to core data. Is there anyway to specify this order using the sort descriptor? SELECT DISTINCT 0, t0.Z_PK FROM ZKDITEM t0 JOIN Z_2TAGS t1 ON t0.Z_PK = t1.Z_2ITEMS WHERE t1.Z_4TAGS = ? ORDER BY t1.Z_FOK_2ITEMS
      singulars
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload