Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>There are a couple of ways to do this.</p> <h2>KVO observer</h2> <p>Your BlogGroup could watch for changes on the Blog entity <code>-numberUnreadPosts</code> property and when it changes it can update itself. </p> <p>Likewise, your Blog can watch for changes on the Post entity <code>-hasBeenRead</code> property and when it changes it can update itself which will propagate up to the BlogGroup.</p> <p>The problem with this design is that it assumes that the BlogGroup and Blog entities are both in memory (because you would turn the observer on in the <code>-awakeFromFetch</code> method). This may not always be the case and I find it best not to rely on that situation.</p> <h2>Propagate the update</h2> <p>When a Post changes the <code>-hasBeenRead</code> property you can override the setter and have it call it's parent (Blog) and tell it about the change. Blog would then update it's own unread count and tell the BlogGroup that it has updated. </p> <p>This design is far more consistent and is unlikely to fail. However it can have unforeseen consequences because of the ripple. When you change a post a number of objects get fetched into memory to be updated.</p> <h2>Or don't worry about it</h2> <p>A third option is that only the post actually has the value. You could then produce a convenience method on both the Blog and the BlogGroup that merely counts the unread from the objects below.</p> <p>This is pretty simple to do but it is not an observable property so may not work in your design.</p> <p>The design of your application will determine which design works better for you. If you know that the BlogGroup and Blog will always be realized when you are working with a post then option one is a better solution imho.</p>
 

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