Code Monkey home page Code Monkey logo

Comments (12)

bjarkehs avatar bjarkehs commented on June 23, 2024

The newest version of the localstorage-adapter is meant for Ember Data beta 5 and onwards. I would consider upgrading. Also make sure you have the newest version of master.

from ember-localstorage-adapter.

oblongta avatar oblongta commented on June 23, 2024

i tried with latest version of ember-data(i.e. ember data beta 6) and even latest version of master but having same problem
is this a bug or some conceptual mistake by me??

from ember-localstorage-adapter.

kurko avatar kurko commented on June 23, 2024

@oblongta I believe that if reload is broken, it is in Ember Data rather than in the adapter. Nonetheless, try doing company.set('person', person) instead of using it in createRecord().

Also, this is wrong:

// you need to use the store to create a record,
// not a model (which is an array in this case)
var a=model.get('employees');
a.createRecord();

Do this instead

var person = this.store.createRecord('person', {
  name: 'pqr',
  department: 'lmn',
});

person.save().then(function(person) {
  person.set('company', model);
  person.save();
});

I ask you to do this because I recently had problems with embedding relations in createRecord().

from ember-localstorage-adapter.

oblongta avatar oblongta commented on June 23, 2024

ok then how do i add person to a company which has hasMany relation with the person??
And The problem is not creating a record or saving it.
The records are created and they are even getting saved but the relation between person and company gets lost i.e. hasMany arrays content gets wiped out .
It is related to the issue mentioned below as i think:
#23

And my code is update version of this jsbin if you look closely:
http://jsbin.com/oKuPev/72/edit

from ember-localstorage-adapter.

bjarkehs avatar bjarkehs commented on June 23, 2024

This is how I do it for a project of mine:

var order = this.get('model');
var user = App.get('currentUser');
order.set('user', user);
order.save().then(function(o) {
    user.get('orders').addObject(order);
    user.save().then(function(u) {
        this.transitionToRoute('order.handle', order, getDateString());
    });
});

Don't get confused with my use of App.get('currentUser') just think of it as your person. You could potentially have created this person already. But the above code saves the records and maintains the hasMany relationship.

My relationships are:

App.User = DS.Model.extend({
    username: DS.attr('string'),
    password: DS.attr('string'),
    orders: DS.hasMany('order')
});

App.Order = DS.Model.extend({
    navision: DS.attr('number'),
    closed: DS.attr('boolean'),
    user: DS.belongsTo('user'),
    hours: DS.hasMany('hour'),
    materials: DS.hasMany('material'),
    services: DS.hasMany('service')
});

from ember-localstorage-adapter.

oblongta avatar oblongta commented on June 23, 2024

Thanxx,
I will look and hope it to get working.
can you tell me whats wrong in this implementation:
http://jsbin.com/oKuPev/72/edit

and my error is same as #23 as it seems to me.
Any method to overcome that

from ember-localstorage-adapter.

oblongta avatar oblongta commented on June 23, 2024

I tried this and getting the same problem:
App.ApplicationController=Ember.ArrayController.extend({
add:function(){
var c= this.store.createRecord('company',{
name:'abc',
turnover:'lmn'
});

var p=this.store.createRecord('person',{
name:'xyz',
department:'pqr'
});

p.save().then(function(p){
p.set('company',c);
p.save().then(function(p){
c.get('employees').addObject(p);
c.save();
});
});
}
});

from ember-localstorage-adapter.

oblongta avatar oblongta commented on June 23, 2024

screenshot from 2014-02-14 22 05 30
this is screen shot before reloading.
You can see person attributes in the template namely xyz and pqr.
Also,in properties tab you see content property has that person record in the array.
However on reloading i get this:
screenshot from 2014-02-14 22 06 06
Now the content property doesnt contain that person record in array and hence no attributes of person are rendered in template.
But however on checking local storage i find that the person exists in local storage:
image

from ember-localstorage-adapter.

bjarkehs avatar bjarkehs commented on June 23, 2024

Ah, now I remember why. I'll have to take a look at it. But try using findAll instead of find.

from ember-localstorage-adapter.

oblongta avatar oblongta commented on June 23, 2024

no findAll doesnt solve the issue.
Is it issue with ember data/local adapter or some conceptual error by me??

from ember-localstorage-adapter.

bjarkehs avatar bjarkehs commented on June 23, 2024

Okay, I know now. As the README states:

Include localstorage_adapter.js in your app and then like all adapters:

App.ApplicationSerializer = DS.LSSerializer.extend();
App.ApplicationAdapter = DS.LSAdapter.extend({
    namespace: 'yournamespace'
});

In the code you linked initially there is no ApplicationSerializer. This serializer handles all the relationships, so without it you're never going to get the relationships.

I will have a closer look at find() since I still expect it to be a little buggy, so use findAll for now.

from ember-localstorage-adapter.

oblongta avatar oblongta commented on June 23, 2024

Thanks for help.
it solved my problem

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.