Simplify your stack and build anything. Or everything.
Build tomorrow’s web with a modern solution you truly own.
Code-based nature means you can build on top of it to power anything.
It’s time to take back your content infrastructure.

lastModifiedBy

default discord avatar
bhavikak.2 years ago
8

i'm checked in users api it's storing multiple objects of lastModifiedBy:{} like shown in image, i want to know the reason

  • default discord avatar
    jessrynkar2 years ago

    oh no that is weird - do you mind sharing your user collection?

  • default discord avatar
    bhavikak.2 years ago
    @854377910689202256

    why not!

  • discord user avatar
    jarrod_not_jared
    2 years ago

    Are you adding lastModifiedBy with a plugin or similar?

  • default discord avatar
    bhavikak.2 years ago
    @281120856527077378

    https://payloadcms.com/docs/plugins/overview#simple-example:~:text=will%20be%20sanitized.-,Simple%20example,-Here%20is%20an

    i'm added from this



    hii

    @281120856527077378

    i'm waiting for your response

  • discord user avatar
    jarrod_not_jared
    2 years ago

    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#config
  • default discord avatar
    bhavikak.2 years ago

    okay so what i have to do now?

  • discord user avatar
    jarrod_not_jared
    2 years ago

    Have you tried either of the things I mentioned above?

  • default discord avatar
    bhavikak.2 years ago

    hiii

    @281120856527077378

    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 on GitHub

Star

Chat on Discord

Discord

online

Can't find what you're looking for?

Get dedicated engineering support directly from the Payload team.