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

Field assignment on record creation #5

Open
velrest opened this issue Aug 14, 2020 · 0 comments
Open

Field assignment on record creation #5

velrest opened this issue Aug 14, 2020 · 0 comments
Assignees
Labels
bug Something isn't working

Comments

@velrest
Copy link
Contributor

velrest commented Aug 14, 2020

Creating model records

If you have your model defined with a @localizedAttr field and directly set the
field on store.createRecord the setter for the field will not be called and
instead of the dictionary with the locale key, the value directly will be assigned
to the field.

The serialized model then looks like this:

{
  "type": "your-model",
  "attributes": {
    "name": "your name"
  } 
}

instead of

{
  "type": "your-model",
  "attributes": {
    "name": {
      "en": "your name"
    }
  } 
}

Solution:
Create your record first and then assign the localized field:

const yourModel = this.store.createRecord("yourModel");
yourModel.name = "this is a test";
@velrest velrest added the bug Something isn't working label Aug 14, 2020
@velrest velrest self-assigned this Aug 14, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant