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

Read-only properties #2782

Open
frbuceta opened this issue Apr 23, 2019 · 4 comments
Open

Read-only properties #2782

frbuceta opened this issue Apr 23, 2019 · 4 comments
Labels
feature Repository Issues related to @loopback/repository package

Comments

@frbuceta
Copy link
Contributor

Is the property readOnly in loopback 4? I've been looking for a while but I have not found anything about it

type: object
properties:
  id:
    # Returned by GET, not used in POST/PUT/PATCH
    type: integer
    readOnly: true
  username:
    type: string
  password:
    # Used in POST/PUT/PATCH, not returned by GET
    type: string
    writeOnly: true
@jannyHou
Copy link
Contributor

jannyHou commented Apr 23, 2019

Since a model property is essentially a TypeScript class property, can you try defining it with readonly keyword like https://www.tutorialsteacher.com/typescript/typescript-readonly?

@model 
class User {
  @property({
    type: 'string',
    id: true,
  })
  readonly id: string;

}

@jannyHou jannyHou self-assigned this Apr 23, 2019
@frbuceta
Copy link
Contributor Author

This does not work for me

  @property({
    type: 'string',
    id: true,
    required: true,
    default: () => {
      return uuid()
    }
  })
  readonly uuid: string;

Captura de pantalla 2019-04-23 a las 23 36 37

Captura de pantalla 2019-04-23 a las 23 36 48

@frbuceta
Copy link
Contributor Author

Can somebody help me?

@bajtos bajtos changed the title Exist readOnly in model? Read-only properties Jun 18, 2019
@bajtos bajtos added the feature label Jun 18, 2019
@bajtos
Copy link
Member

bajtos commented Jun 18, 2019

AFAIK, LoopBack 4 does not support readonly properties yet.

@bajtos bajtos added the Repository Issues related to @loopback/repository package label Jun 18, 2019
@jannyHou jannyHou removed their assignment May 4, 2020
@stale stale bot added the stale label Dec 25, 2020
@frbuceta frbuceta removed the stale label Apr 8, 2021
@loopbackio loopbackio deleted a comment from stale bot Apr 8, 2021
@stale stale bot added the stale label Oct 5, 2021
@loopbackio loopbackio deleted a comment from stale bot Oct 5, 2021
@stale stale bot removed the stale label Oct 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature Repository Issues related to @loopback/repository package
Projects
None yet
Development

No branches or pull requests

3 participants