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

enableAutoId has no effect #1214

Open
angabriel opened this issue Sep 9, 2024 · 1 comment
Open

enableAutoId has no effect #1214

angabriel opened this issue Sep 9, 2024 · 1 comment
Assignees
Labels

Comments

@angabriel
Copy link

angabriel commented Sep 9, 2024

Used libraries

core, jsonapi, angular-jsonapi

Library version(s)

@datx/core 3.0.0, @datx/jsonapi 3.0.0, @datx/jsonapi-angular 3.0.0

Sample API response (if relevant)

No response

Environments with the issue

Everwhere

Environments without the issue

No response

Current behavior

class MyJsonModel extends jsonapiAngular(Model) {
  @Field({ isIdentifier: true, enableAutoId: false })
  public id!: string;
}

When I do new MyJsonModel() I get ids like "-1", "-2" and so on. So Its hard to differntiate between models that need to be created (POST) oder updated (PATCH).

Expected behavior

The id should be undefined or null when doing

@Field({ isIdentifier: true, enableAutoId: false })
  public id?: string;`

Reproduction steps

1.
2.
3.
...
@DarkoKukovec
Copy link
Member

Sorry for a late reply.
I understand that this might be weird, but datx needs some type of an id internally. enableAutoId: false is mostly meant for cases when you're already providing your own id. You could technically override this with static getAutoId() on the model, but as soon as you have two same values, things would start breaking.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants