Code Monkey home page Code Monkey logo

Comments (9)

kurko avatar kurko commented on June 23, 2024

Does record.destroy() work?

Do you think you would be able to send a PR with a failing spec? There are many there already in which you can mirror.

from ember-localstorage-adapter.

oblongta avatar oblongta commented on June 23, 2024

I don't know if i am right but on seeing code of local_adapter.js I find that deleteRecord doesnt deal with serialization whereas update and create do.Maybe thats why error is creeping.
Here is snippet of code:

  createRecord: function (store, type, record) {
    var namespaceRecords = this._namespaceForType(type),
        recordHash = record.serialize({includeId: true});

    namespaceRecords.records[recordHash.id] = recordHash;

    this.persistData(type, namespaceRecords);
    return Ember.RSVP.resolve();
  },

  updateRecord: function (store, type, record) {
    var namespaceRecords = this._namespaceForType(type),
        id = record.get('id');

    namespaceRecords.records[id] = record.serialize({ includeId: true });

    this.persistData(type, namespaceRecords);
    return Ember.RSVP.resolve();
  },

  deleteRecord: function (store, type, record) {
    var namespaceRecords = this._namespaceForType(type),
        id = record.get('id');

    delete namespaceRecords.records[id];

    this.persistData(type, namespaceRecords);
    return Ember.RSVP.resolve();
  }

from ember-localstorage-adapter.

oblongta avatar oblongta commented on June 23, 2024

Any views on this problem??

from ember-localstorage-adapter.

kurko avatar kurko commented on June 23, 2024

@oblongta I'm not working on any project using LS right now, but I can review code help with what I can do.

Do you think you would be able to send a PR with a failing spec? There are many there already in which you can mirror.

That way I could take a quick look and debug fast.

from ember-localstorage-adapter.

bjarkehs avatar bjarkehs commented on June 23, 2024

Most frameworks have special commands to handle deletion of relationship records, such as belongsTo and hasMany. Ember Data generally does not handle these cases and you seem to have to delete everything you want deleted. So if you want to delete, say an employee, from a company, where company hasMany employees. Then I assume the way is to first remove the employee from the company through something like this:

var employee = this.get('model');
var company = employee.get('company');
company.get('employees').removeObject(employee);
company.save();
employee.deleteRecord();
employee.save();

This should delete the employee for good.

from ember-localstorage-adapter.

kurko avatar kurko commented on June 23, 2024

@oblongta can we close this?

from ember-localstorage-adapter.

mohamnag avatar mohamnag commented on June 23, 2024

I'm using LS with ember data 1.0.0 beta 8.
lets take the employee and company example, when I load all the records from LS, then following will delete both employee and also its relation in company:

var employee = this.get('model');
var company = employee.get('company');

employee.deleteRecord();
employee.save().then(function(){
    company.save();
});

however when the record for employee is just created on the same session (and is added to company.employees using addObject, that code does remove the employee record but NOT the relation in company.

I'm not an ember profi so I cant say if this is a ember data problem that does not maintain the relation for newly created records or is it from LS.

however the code @bjarkehs provided always does the right job.

from ember-localstorage-adapter.

jkowens avatar jkowens commented on June 23, 2024

@mohamnag That's an ember data issue. I ran into the same problem using the DS.ActiveModelAdapter. Thankfully I found this thread and another one that further describes the issue. emberjs/data#1303

from ember-localstorage-adapter.

locks avatar locks commented on June 23, 2024

I also believe this to be an Ember Data problem and thus not specific to LSA.

from ember-localstorage-adapter.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.