Skip to content

isDirty with associations returning true after instances are saved and then re-fetched from server #108

Open
@Dishwasha

Description

@Dishwasha

I have a many-many relationship graph that I save to the server. When I re-fetch all the resources, isDirty reports a dirty resource but the individual graph of resources report themselves as not dirty. The particular scenario I'm seeing this on is when the graph of resources was saved with new items and not just edits.

@Model()
class Forum extends ApplicationResource
  @HasMany() topics: Topic[]

@Model()
class Topic extends ApplicationResource
  @BelongsTo() forum: Forum
  @HasMany() posts: Post[]

@Model()
class Post extends ApplicationResource
  @BelongsTo() topic: Topic

this.forums = (await Forum.includes({topics: 'posts'}).all()).data

///... Add posts to topics ...
forums.save()

this.forums = (await Forum.includes({topics: 'posts'}).all()).data

this.forums.find(t => t.isDirty({topics: 'posts'})) === true
forums[index].isDirty() === false
forums[index].topics[index].isDirty() === false
forums[index].topics[index].isDirty('posts') === true && false depending on index of topic
forums[index].topics[index].posts[index].isDirty() === false

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions