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

HasOne findExistingLinksFor has improper method signature #535

Open
jayeb opened this issue Mar 28, 2019 · 2 comments · May be fixed by #575
Open

HasOne findExistingLinksFor has improper method signature #535

jayeb opened this issue Mar 28, 2019 · 2 comments · May be fixed by #575
Labels
mapper relations Mapper relations are the ability to define a relationship one Mapper has with another Mapper

Comments

@jayeb
Copy link

jayeb commented Mar 28, 2019

Description

The "parent" record on a hasOne/belongsTo relationship doesn't appear to link correctly, even when the child record already exists in the datastore. I think this is due to the findExistingLinksFor method defined on the HasOne relationship class having an improper method signature.

Environment

  • js-data version: 3.0.2

Steps to reproduce

The HasOne.findExistingLinksFor method is looking for two arguments:

findExistingLinksFor (relatedMapper, record) { ...

But the HasMany.findExistingLinksFor and BelongsTo.findExistingLinksFor methods both look for two arguments:

findExistingLinksFor (record) { ...

Best I can tell, this method is only ever called in one place (Line 146 of Relation.js), and the arguments passed in match the HasMany and BelongsTo method signatures:

relatedData = this.findExistingLinksFor(record)

I forked the repo and tried this locally:

findExistingLinksFor (record) {
  const relatedMapper = this.getRelation()
  const recordId = utils.get(record, relatedMapper.idAttribute)
  const records = this.findExistingLinksByForeignKey(recordId)

  if (records && records.length) {
    return records[0]
  }
},

But apparently this.getRelation() chokes unless the child record's Mapper was defined before the parent record's Mapper. I think I've taken this about as far as I can at this point, hoping someone with a better working knowledge of the inner mechanisms here can swoop in and help out.

@crobinson42
Copy link
Member

@jayeb failing test?

@crobinson42
Copy link
Member

Or if there’s not test hitting this logic case can you write one to help resolve?

@crobinson42 crobinson42 added the mapper relations Mapper relations are the ability to define a relationship one Mapper has with another Mapper label Jan 26, 2020
@patricklx patricklx linked a pull request Mar 26, 2021 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
mapper relations Mapper relations are the ability to define a relationship one Mapper has with another Mapper
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants