Skip to content

Relationship config key doesn't seem to get used when saving a model #210

@WimWidgets

Description

@WimWidgets

The relationship config property key, to convert property names, only seems to work for incoming data and not for outgoing data (saving). I haven't experienced this issue with the similar attribute config property serializedName.

For example converting between camel case and dasherized.

@JsonApiModelConfig({type: 'endpoints/things'})
export class Thing extends JsonApiModel {

    @BelongsTo({key: 'foo-bar'})
    fooBar: FooBar;
}

@JsonApiModelConfig({type: 'endpoints/foo-bars'})
export class FooBar extends JsonApiModel { }

For every retrieved Thing the fooBar property is properly set by the foo-bar property coming from the API. Saving a new Thing with a set fooBar property sends this property as fooBar to the API instead of foo-bar.

Payload to the server

{
  "data": {
    "relationships": {
      "fooBar": {
        "data": {
          "type": "endpoints/foo-bars",
          "id": "1"
        }
      }
    },
    "type": "endpoints/things",
    "attributes": {}
  }
}

Is this a bug or am I missing something?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions