title: How do I execute a subquery as an attribute using Core Data?
body: <p>I have an entity named "Genre" that has attributes genreID and parentGenreID.  I want to make a dynamic attribute that gives me the count of Genre entities where parentGenreID is equal to the row's genreID so that I don't have to query for the count for each returned row.</p>
  
  <p>If I was doing this in SQL, I'd use the query:</p>
  
  <p><code>SELECT g.title, (SELECT COUNT(*) FROM genres sg WHERE sg.parentGenreID = g.genreID) as subgenres FROM genres g</code></p>
  
  <p>I was thinking perhaps a Fetched Property would be the answer, but those seem to be returned as NSArrays, and still I'm trying to figure out what the appropriate syntax would be.</p>
  
  <p>My best guess is something like:</p>
  
  <p><code>SUBQUERY(Genre, $genre, $genre.parentGenreID = $FETCH_SOURCE.genreID).@count</code></p>
  
  <p>What would be the right way to do this in Core Data?</p>