question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Loading lazy associations via Related Resource Links causes association to be dirty

See original GitHub issue

I’ve managed to isolate the issue I was seeing when I commented on #28.

When an association is loaded via a related resource link and there is no data linkage for this association (i.e. missing the ‘id’ and ‘type’) then the association is considered to be changed, thus dirtying the model.

JSON API example e.g.

{
  "data": {
    "type": "project",
    "attributes": {
      "title": "Project1"
    },
    "id": 1,
    "relationships": {
      "company": {
        "links": {
          "related": "/projects/1/company"
        }
      }
    }
  }
}

I’ve written a breaking test for belongsTo and hasMany associations to demonstrate the problem. I’ll push it to a branch shortly

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:8 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
danielspanielcommented, Sep 20, 2019

Sure thing @richardfrosztega , best thing is to clone this repo, and make a PR for your branch in your repo against mine. Thanks for working on it. I appreciate it and others will too.

0reactions
richardfrosztegacommented, Sep 20, 2019

I’ve been working on a fix based on this from inside ember data Relationship

/*
       This flag indicates whether we should
        re-fetch the relationship the next time
        it is accessed.
        The difference between this flag and `shouldForceReload`
        is in how we treat the presence of partially missing data:
          - for a forced reload, we will reload the link or EVERY record
          - for a stale reload, we will reload the link (if present) else only MISSING records
        Ideally these flags could be merged, but because we don't give the
        request layer the option of deciding how to resolve the data being queried
        we are forced to differentiate for now.
        It is also possible for a relationship to remain stale after a forced reload; however,
        in this case `hasFailedLoadAttempt` ought to be `true`.
      false when
        => recordData.isNew() on initial setup
        => a previously triggered request has resolved
        => we get relationship data via push
      true when
        => !recordData.isNew() on initial setup
        => an inverse has been unloaded
        => we get a new link for the relationship
      TODO @runspired unskip the acceptance tests and fix these flags
     */
    this.relationshipIsStale = false;

I just need some time to tidy it up from POC to production ready. Once I’ve got it together would you like me to put it on a branch @danielspaniel?

Read more comments on GitHub >

github_iconTop Results From Across the Web

5 ways to initialize lazy associations and when to use them
Initializing an association the right ways makes the difference between horrible and great performance. Here are 5 different ways and when to use...
Read more >
How to tell if a relationship has been loaded #5629 - GitHub
Loading lazy associations via Related Resource Links causes association to be dirty danielspaniel/ember-data-change-tracker#66.
Read more >
5 ways to initialize lazy associations and when to use them
Lazy loading of associated entities is a well-established best practice in JPA. Its main goal is to retrieve only the requested entities ...
Read more >
6 Object Relational Mapping (GORM) 3.0.16
They are linked together through relationships; one-to-one, one-to-many, or many-to-many. GORM is Grails' object relational mapping (ORM) implementation.
Read more >
The best way to handle the LazyInitializationException
For this reason, it's better to use LAZY associations. A LAZY association is exposed via a Proxy, which allows the data access layer...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found