i'm checked in users api it's storing multiple objects of lastModifiedBy:{} like shown in image, i want to know the reason
oh no that is weird - do you mind sharing your user collection?
@jesschow why not!
Are you adding lastModifiedBy with a plugin or similar?
@Jarrod
https://payloadcms.com/docs/plugins/overview#simple-example:~:text=will%20be%20sanitized.-,Simple%20example,-Here%20is%20an
i'm added from this
hii @Jarrod i'm waiting for your response
So what I see is what I would expect, I think. The shape you are seeing is not what is stored in the db, the db just stores the value as id and the relationTo. If you set a
depth
parameter in your query params
?depth=1
what do you get?
Think about it if the last modified was another user, it would fulfill that user and they would have a last modified field, that would get fulfilled and so on. The only thing here is, it’s a circular reference so you need a way to break the chain. I would likely create another field
lastModifiedBySelf
and then check the user id on the request with the id on
originalDoc
, if they match set the new checkbox and clear the relationship, else set the relationship.
See all arguments for beforeChange hook here
https://payloadcms.com/docs/hooks/collections#beforechange
OR, you could set
maxDepth
on the relationship field, probably more-so what you are looking for.
https://payloadcms.com/docs/fields/relationship#configokay so what i have to do now?
Have you tried either of the things I mentioned above?
hiii @Jarrod i tried it. if i passed depth=1 i got "lastModifiedBy": {
"value": {
"id": "633aa17cd6c8ab006231e6b3",
"email": "------------",
"createdAt": "2022-10-03T08:46:52.557Z",
"updatedAt": "2023-03-29T10:10:27.673Z",
"enableAPIKey": false,
"lastModifiedBy": {
"value": "633aa17cd6c8ab006231e6b3",
"relationTo": "users"
},
"name": "Bhavika ",
"roles": [
"admin"
]
},
"relationTo": "users"
}, and i save page by another user and i set depth=60 it's fullfill the user with adding new object.
so on a each save it's adding new object
Star
Discord
online
Get help straight from the Payload team with an Enterprise License.