Skip to content
Discussion options

You must be logged in to vote

Yes, this can be done w/ hooks and access control. Here is an example collection:

const Posts: CollectionConfig = {
  slug: 'posts',
  hooks: {
    beforeChange: [
      ({ req, operation, data }) => {
        if (req.user) {
          if (operation === 'create') {
            data.updatedBy = req.user.id;
            data.createdBy = req.user.id;
          } else if (operation === 'update') {
            data.updatedBy = req.user.id;
          }
          return data;
        }
      },
    ],
  },
  fields: [
    {
      name: 'createdBy',
      type: 'relationship',
      relationTo: 'users',
      access: {
        update: () => false,
      },
      admin: {
        readOnly: true,

Replies: 2 comments 2 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
2 replies
@Stupidism
Comment options

@palak-convivity
Comment options

Answer selected by denolfe
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
4 participants