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

Handling kebab-cased relationship #235

Open
GIANTCRAB opened this issue Aug 2, 2019 · 4 comments
Open

Handling kebab-cased relationship #235

GIANTCRAB opened this issue Aug 2, 2019 · 4 comments

Comments

@GIANTCRAB
Copy link

GIANTCRAB commented Aug 2, 2019

Hello,

Thanks for this amazing library. I've been using it for the past few days and encountered an issue with regards to relationship. I'm currently using version 7.1.2 with Angular v8.

In the Campaign model, I've got several types

  campaigns
  campaign-proposals
  companies

The following is my model with a one-to-many relationship

@JsonApiModelConfig({
  type: 'campaigns'
})
export class Campaign extends JsonApiModel {
  @HasMany()
  companies: Company[];

  @HasMany()
  campaignProposals: CampaignProposal[];
}

When retrieving record, I checked that the network has received it:
Screenshot from 2019-08-03 00-40-52

Company was parsed correctly but the console output did not give me campaignProposals:
Screenshot from 2019-08-03 00-42-22

Am I doing something wrong here? Thank you!

@GIANTCRAB
Copy link
Author

GIANTCRAB commented Aug 2, 2019

I figured. A simple workaround this would be the following:

@JsonApiModelConfig({
  type: 'campaigns'
})
export class Campaign extends JsonApiModel {
  @HasMany()
  companies: Company[];

  @HasMany()
  'campaign-proposals': CampaignProposal[];
}

If there's a better approach to this, please let me know. Thanks

@hpawe01
Copy link
Contributor

hpawe01 commented Aug 3, 2019

Have a look at this issue: #210

You could do @HasMany({key: 'campaign-proposals'}) and just use your custom property (like campaignProposals)

@GIANTCRAB
Copy link
Author

Thanks @hpawe01

Can I do a PR to update the README with this info? I think it'll be rather useful

@hpawe01
Copy link
Contributor

hpawe01 commented Aug 5, 2019

Sure, PRs that improve the README are definitely welcome altough I am not in the position to decide this, but more @safo6m or @HennerM. But I am sure they be glad as well, so just create it and wait for comments and approval.

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

No branches or pull requests

2 participants