Note that there are some explanatory texts on larger screens.

plurals
  1. POSorting an NSFetchRequest Based on a Property within a One-to-Many Relationship?
    primarykey
    data
    text
    <p>I've been prowling through the SO search results and can't (thus far) find an answer to this question.</p> <p>Given a data entity A that has a one-to-many relationship to entity B, is there any way to have my NSFetchedResult sort on a <em>property</em> of entity B. i.e. Can I have my sort descriptor key drill down into entity B? I've tried dot notation, etc, but nothing is working.</p> <p>e.g. Entity A has a relationship <code>inEntityB</code>. Entity B has a property <code>entityBproperty</code>. How can I sort a list of Entity A's based on the <code>entityBproperty</code> value of their respective <code>inEntityB</code> relationships?</p> <p>Something like (and no this doesn't work):</p> <pre><code>request.sortDescriptors = [NSArray arrayWithObjects: [NSSortDescriptor sortDescriptorWithKey:@"entityAproperty" ascending:NO selector:@selector(localizedStandardCompare:)], [NSSortDescriptor sortDescriptorWithKey:@"inEntityB.entityBproperty" ascending:NO selector:@selector(localizedStandardCompare:)], nil]; </code></pre> <p>It seems awfully inefficient to duplicate, in Entity A, the <code>entityBproperty</code> that I want to sort by. Isn't the whole point of relationships that you can compartmentalize your data model to keep it more manageable?</p> <p>Any advice much appreciated! Thanks!</p> <p><strong>Edit:</strong> I'm not really sure what additional information I can add to help clarify the question, but given the lack of response thus far, if anyone has suggestions for what else I might add here, I'm all ears. Unfortunately I don't have bounty privileges yet, or I'd consider one in this case, as this seems like a potentially more obscure question.</p>
    singulars
    1. This table or related slice is empty.
    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.
 

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