Skip to content

Model saving after inserting creates a double instance #85

Open
@JelleScheer

Description

@JelleScheer

Hi!

In my use case I want to create an empty version of a model (let's call it Post) and after filling it I want to save it to the database and sync it with the empty version.

The example flow would be:

Post.insert({ data: { title: 'Basic title' } }).then((new_post) => {
     Post.api().post('', new_post.posts[0]);
  });

The insert function creates a new empty instance of the model, and if I look in the store it's visible as _no_key_1. After sending the empty instance along to the api().post() method it creates a new instance instead of replacing/syncing _no_key_1 with the response, so ultimately I have two instances in my store: _no_key_1 and an instance with the ID that was just stored in the database.

What can I do to sync the response with _no_key_1?

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions