These are chat archives for js-data/js-data

25th
Sep 2015
Nelo Mitranim
@Mitranim
Sep 25 2015 00:12
also fixes an unrelated problem with eval I just ran into
Jason Dobry
@jmdobry
Sep 25 2015 00:13
orthogonal problem should be addressed in a different issue/PR
Nelo Mitranim
@Mitranim
Sep 25 2015 00:13
agreed
didn't know a new commit in the same unmerged branch would be a part of the same PR
I can just force-revert the commit for now
should be fine now
Jason Dobry
@jmdobry
Sep 25 2015 00:20
@angelxmoreno Yes, there is extra goodness. The first is that your frontend and backend will speak each other's language (the query syntax). Check out https://github.com/js-data/js-data-examples
Nelo Mitranim
@Mitranim
Sep 25 2015 00:21
js-data/js-data#222
I have a model called Element with a methods object in the definition, and before this change, js-data would try and use the native Element constructor instead!
Angel S. Moreno
@angelxmoreno
Sep 25 2015 10:08
thanks @jmdobry . I will check it out
Nelo Mitranim
@Mitranim
Sep 25 2015 10:37
Any advice on optimistic updates? I want my create and destroy calls to inject or remove new instances immediately and roll back the changes if the ajax promise is rejected
The difficulty is that injection requires an id attribute, which by definition is missing when we're creating a new object and waiting for the server to tell us the id
Robert P
@robertdp
Sep 25 2015 11:33
For creation you could use a unique fake id, and when the server returns the newly created object with its real id eject the temporary fake one from the store to avoid duplication.
Nelo Mitranim
@Mitranim
Sep 25 2015 11:34
Thanks, that's what I'm trying to do already
Robert P
@robertdp
Sep 25 2015 11:50
Something that caught me in the past was trying to create a composite resource that only existed client-side, from two or more resources returned by the server.
Not fun... :/
Robert P
@robertdp
Sep 25 2015 11:57
Basically the API dev had over-normalised the database trying to remove all redundancy, and made it not only more redundant but also much harder to get the data needed for each view in the UI.
Nelo Mitranim
@Mitranim
Sep 25 2015 11:58
haha
Sergii
@Pencroff
Sep 25 2015 13:44
@robertdp for hasOne relation was bug that I have fixed in #224
@jmdobry I am not so familiar what process for pull requests, just fix bug (with test cases), create issue and made pull request. Clarify please if I miss something.
Jason Dobry
@jmdobry
Sep 25 2015 14:53
@Mitranim I believe DS#destroy and DS#destroyAll have an eagerEject option which defaults to false. For eager injection, js-data/js-data#197 there is an open issue.
Cameron McCallie
@c-mac
Sep 25 2015 16:05
Hey @jmdobry! Thanks for the awesome library. I’m having an issue implementing server-side pagination. I’m using a custom adapter that wraps wraps our own http service to make API requests. myResource.findAll() returns a data structure like: {data: [{}, … {}], totalCount: 1337} . I want to inject JUST the array of objects into the store, whilst still saving the totalCount to a variable. If I don’t set cacheResponse: false in the resource definition, it breaks because js-data is trying to inject the object that contains both the count and the array into the store, which obviously fails since there is no id field. Any thoughts here? I thought that the solution would involve a beforeInject hook that just injects the myResources, but I’m not sure how to do that whilst still returning the totalCount.
Scott Trenda
@ScottTrenda
Sep 25 2015 16:46
In js-data 2.0+, what happens when it can't find a Promise constructor? (i.e. in IE?) I see an error message in the console, but the data seems to load just fine beyond that.
Nelo Mitranim
@Mitranim
Sep 25 2015 17:25
@jmdobry Nice, thanks!
Andrew E. Rhyne
@thebigredgeek
Sep 25 2015 21:38
Question:
var foo = DS.defineResource({
  name: 'Foo',
  endpoint: '/foos',
  idAttribute: 'guid',
  keepChangeHistory: true,
  schema: {
    'name': 'string'
  },
  relations: {
    belongsTo: {
      'Bar': {
        localKey: 'bar',
        localField: 'bar_guid',
        parent: true
      }
    }
  }
});

var bar = DS.defineResource({
  name: 'Bar',
  idAttribute: 'guid',
  endpoint: '/bars',
  keepChangeHistory: true,
  relations: {
    hasMany: {
      'Foo': {
        localField: 'foo',
        foreignKey: 'bar_guid'
      }
    }
  }
});

var barInst = bar.inject({
  guid: 'abc123'
});

barInst.DSLoadRelations('Foo');

//Makes request to /foos rather than /bars/abc123/foos
This message was deleted
Why does the URL compose the wrong way, as mentioned above?
I would expect /bars/abc123/foos but instead get /foos when I load barInst relations
Any thoughts?
@jmdobry
Andrew E. Rhyne
@thebigredgeek
Sep 25 2015 21:59
actually, I am getting /foos?bar_guid=abc123
Andrew E. Rhyne
@thebigredgeek
Sep 25 2015 22:14
anyone here?
Jason Dobry
@jmdobry
Sep 25 2015 22:34
nope, at work