Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Docs] Query Builder #689

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 11 additions & 0 deletions docs/relations.md
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,17 @@ const postsByUser: Post[] = await photon.posts

Note that, if you query a relationship, you must specify the fields (`id`) you want to search for.

Due to the fact, that photon acts as a Query Builder, you can "reuse" specific parts over and over again if you have to query the same instances. Consider the following example:

```ts
// note the missing await here!
const currentUserBuilder = photon.users.findOne({ where: { id: currentUserId } });

// now you have a query builder that you can reuse and append onto this!
const postsOfUser = await currentUserBuilder.posts();
const profileOfUser = await currentUserBuilder.profile();
```

### Nested writes (transactions)

Nested writes provide a powerful API to write relational data to your database. They further provide _transactional guarantees_ to create, update or delete data across multiple tables in a single Photon.js API call. The level of nesting of a nested writes can be arbitrarily deep.
Expand Down