Query data across slices
Goal: a screen needs data that doesn’t live in a single slice — authors with their books, an order with its line items, anything where one thing owns a list of another.
Keep the relationship explicit
Section titled “Keep the relationship explicit”In a database-backed Arc slice, model the relationship the same way you would in the domain: the child carries the parent’s id, and the query filters by it. Arc’s part is making that query a typed, live endpoint and generating the React proxy that calls it.
For an owns-a-list relationship, keep the child keyed to its parent. A book belongs to an author, so the Book read model carries AuthorId:
[ReadModel]public record Book([property: Key] BookId Id, AuthorId AuthorId, BookTitle Title){ public static ISubject<IEnumerable<Book>> BooksForAuthor([Key] AuthorId authorId, IMongoCollection<Book> books) => books.Observe(book => book.AuthorId == authorId);}The generated proxy takes the same parameter:
const [books] = BooksForAuthor.use(authorId);Because the query returns Observe(...), it stays live. Add a book for that author and the row updates without polling.
For a list-with-details screen, let the author list call AllAuthors.use() and each row call BooksForAuthor.use(author.id). That keeps each slice small: the author slice owns authors, the book slice owns books, and the screen composes their generated proxies.
See also
Section titled “See also”- Queries — observable and non-observable query methods, parameters, and filtering.
- Relate your slices — this relationship built step by step.
- Run a command from React — consuming the query proxy.