8000 HasOne `findExistingLinksFor` has improper method signature · Issue #535 · js-data/js-data · GitHub
[go: up one dir, main page]

Skip to content
HasOne findExistingLinksFor has improper method signature #535
Open
@jayeb

Description

@jayeb

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    mapper relationsMapper relations are the ability to define a relationship one Mapper has with another Mapper

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0