[v5] Using firstOrCreate() - how to tell if record was found or created? #2495
-
Is there a way to determine if a model was just created or if an existing record was returned when using |
Beta Was this translation helpful? Give feedback.
Answered by
thetutlage
Apr 19, 2021
Replies: 2 comments
-
Yup, using the const user = await User.firstOrCreate(search, payload)
if (user.$isLocal) {
// no rows found in db. Hence a new one is created
} else {
// existing db row
} |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
e-e
-
Hi! Can i use find with local records? |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Yup, using the
$isLocal
property