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

fix (crud): update idempotent methods to match argument's order #19

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions content/docs/models/crud_operations.md
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ await User.firstOrCreate(searchPayload, savePayload)

### fetchOrCreateMany

The `fetchOrCreateMany` is similar to the `firstOrCreate` method, but instead, you can create more than one row. The method needs a unique key for finding the duplicate rows and an array of objects to persist (if missing inside the database).
The `fetchOrCreateMany` is similar to the `firstOrCreate` method, but instead, you can create more than one row. The method needs an array of objects to persist (if missing inside the database) and a unique key for finding the duplicate rows.

```ts
import User from '#models/user'
Expand All @@ -243,7 +243,7 @@ const usersToCreate = [
},
]

await User.fetchOrCreateMany('email', usersToCreate)
await User.fetchOrCreateMany(usersToCreate, 'email')
```

### updateOrCreate
Expand All @@ -261,7 +261,7 @@ await User.updateOrCreate(searchPayload, persistancePayload)

### updateOrCreateMany

The `updateOrCreateMany` method allows syncing rows by avoiding duplicate entries. The method needs a unique key for finding the duplicate rows and an array of objects to persist/update.
The `updateOrCreateMany` method allows syncing rows by avoiding duplicate entries. The method needs an array of objects to persist/update and a unique key for finding the duplicate rows.

```ts
import User from '#models/user'
Expand All @@ -278,7 +278,7 @@ const usersToCreate = [
},
]

await User.updateOrCreateMany('email', usersToCreate)
await User.updateOrCreateMany(usersToCreate, 'email')
```

In this example, we use both the email and username as keys to find duplicates. If a row already exists with the same combination of email and username, it will be updated with the new provided values.
Expand All @@ -302,5 +302,5 @@ const usersToCreate = [
},
]

await User.updateOrCreateMany(['email', 'username'], usersToCreate)
await User.updateOrCreateMany(usersToCreate, ['email', 'username'])
```