Originally created by @zachwaugh on GitHub (Aug 8, 2019).
I'm currently creating a list monitor by building a query, but I'm wondering if there is a simpler way. For example, if I have a Post entity which has many Authors (and Author has many Posts), I need to do something like this to get a live list of all the posts from an author:
letauthor:Author=// assume I have this from another queryletmonitor=CoreStore.monitorList(From<Post>().where(format:"authors CONTAINS %@",author).orderBy(.descending(\.createdAt)))
But would I love to do this:
letmonitor=CoreStore.monitorList(author.posts)
Is there any way to do something along those lines instead of recreating the full query?
Originally created by @zachwaugh on GitHub (Aug 8, 2019).
I'm currently creating a list monitor by building a query, but I'm wondering if there is a simpler way. For example, if I have a `Post` entity which has many `Author`s (and `Author` has many `Posts`), I need to do something like this to get a live list of all the posts from an author:
```swift
let author: Author = // assume I have this from another query
let monitor = CoreStore.monitorList(
From<Post>()
.where(format: "authors CONTAINS %@", author)
.orderBy(.descending(\.createdAt))
)
```
But would I love to do this:
```swift
let monitor = CoreStore.monitorList(author.posts)
```
Is there any way to do something along those lines instead of recreating the full query?
NSFetchResultsController, which ListMonitor uses internally, does not support observing on relationships. You might want to create a denormalized entity between Post and Author that will contain one row for each author for a particular post, observe that list, extract an array of objectIDs on didChange, and fetch the list of Posts using the objectIDs.
@JohnEstropia commented on GitHub (Aug 13, 2019):
`NSFetchResultsController`, which `ListMonitor` uses internally, does not support observing on relationships. You might want to create a denormalized entity between `Post` and `Author` that will contain one row for each author for a particular post, observe that list, extract an array of objectIDs on didChange, and fetch the list of `Post`s using the objectIDs.
Thanks for the answer! It's not too bad to recreate the query, just hoping to avoid the redundancy if possible.
@zachwaugh commented on GitHub (Aug 13, 2019):
Thanks for the answer! It's not too bad to recreate the query, just hoping to avoid the redundancy if possible.
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
Originally created by @zachwaugh on GitHub (Aug 8, 2019).
I'm currently creating a list monitor by building a query, but I'm wondering if there is a simpler way. For example, if I have a
Postentity which has manyAuthors (andAuthorhas manyPosts), I need to do something like this to get a live list of all the posts from an author:But would I love to do this:
Is there any way to do something along those lines instead of recreating the full query?
@JohnEstropia commented on GitHub (Aug 13, 2019):
NSFetchResultsController, whichListMonitoruses internally, does not support observing on relationships. You might want to create a denormalized entity betweenPostandAuthorthat will contain one row for each author for a particular post, observe that list, extract an array of objectIDs on didChange, and fetch the list ofPosts using the objectIDs.@zachwaugh commented on GitHub (Aug 13, 2019):
Thanks for the answer! It's not too bad to recreate the query, just hoping to avoid the redundancy if possible.