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

23rd
Sep 2015
Robert P
@robertdp
Sep 23 2015 00:20
And when do you estimate 2.4 will be released?
Jason Dobry
@jmdobry
Sep 23 2015 01:48
I could release today, but that would require updating the docs for everything in the release.
JWoodJr
@JWoodJr
Sep 23 2015 03:09
Hi I'm not sure if this is where to put this but I'm working working js-data on angular and ran into a snag, hoping I could get a hand
Jason Dobry
@jmdobry
Sep 23 2015 03:16
so, what's the snag?
JWoodJr
@JWoodJr
Sep 23 2015 03:17
I'm using DS.create() and passing in the object to be created, nothing else. It runs through the promses in js-data-debug.js until the 6 or 7th one where the attrs' value is suddenly undefined
Jason Dobry
@jmdobry
Sep 23 2015 03:18
your code? and what is your server's response?
JWoodJr
@JWoodJr
Sep 23 2015 03:18
eventually leading to this outut Error: support.inject: "attrs" must be an object or an array!
my exact code is ```
let support = Support.createInstance(contact);
  support.DSCreate()
    .then(function(email) {

      console.log('inside the first then');
      console.log('email', email);

      Support.DSSave(email, {info: 'info'})
        .then(function(email) {
          console.log('saved email', email);
          console.log('saved thing', thing);
          alert('totally right');
        }, function(err) {
          console.log('saved error', err);
          alert('totally wrong');
        });
    });```
Jason Dobry
@jmdobry
Sep 23 2015 03:26
This message was deleted
DS#save saves an item in its current state, so you want to use DS#update if you want to pass in the attributes with which to update the item:
return Support.create().then(function (support) {
  support.info = 'info';
  return Support.save(support.id);
}).then(function (support) {...});
return Support.create().then(function (support) {
  return Support.update(support.id, { info: 'info' });
}).then(function (support) {...});
But I suspect it's your server response that's causing the error.
Jason Dobry
@jmdobry
Sep 23 2015 03:31
This plunker shows an example expected response: http://plnkr.co/edit/HQ6dEM?p=info
JWoodJr
@JWoodJr
Sep 23 2015 03:37
I believe you've solved my problem
thank you!
Robert P
@robertdp
Sep 23 2015 04:04
and my server now has it's first scope implemented. thanks for your work @jmdobry !
Sergii
@Pencroff
Sep 23 2015 08:26

He guys @/all. Did somebody face issue with id = 0 (zero) in relations? I have some model that has relation and if some relation doesn't exist server provide response with default value and id = 0
For example I have response:

{
    Id: 123,
    Value: 'Some value',
    ClientId: 0,
    Client: {
        ClientId: 0,
        ClientName: 'Default Client'
    }
}

and model:

var model = store.defineResource({
    name: 'itemModel',
    endpoint: '/item',
    idAttribute: 'Id',
    relations: {
        hasOne: {
            'clientModel': {
                localField: 'Client',
                localKey: 'ClientId'
            }
        }
    }
})

but after loadRelations I have undefined in Client property. How I could get my value from response?

Robert P
@robertdp
Sep 23 2015 12:47
@Pencroff Are you sure that shouldn't be a belongsTo relation instead?
Sergii
@Pencroff
Sep 23 2015 14:08
@robertdp I don't have Id of item inside clientModel. It has has relation instead of belong.
Robert P
@robertdp
Sep 23 2015 15:23
If each item has a clientId, then the relation is itemModel belongsTo clientModel. The inverse of that is clientModel hasOne/hasMany itemModel.
var itemModel = store.defineResource({
    name: 'itemModel',
    endpoint: '/item',
    idAttribute: 'Id',
    relations: {
        belongsTo: {
            'clientModel': {
                localKey: 'ClientId', // itemModel.ClientId == clientModel.Id
                localField: 'Client' // itemModel.Client == clientModel.get(itemModel.ClientId)
            }
        }
    }
});
var clientModel = store.defineResource({
    name: 'clientModel',
    endpoint: '/client',
    idAttribute: 'Id',
    relations: {
        hasOne: {
            'itemModel': {
                foreignKey: 'ClientId', // clientModel.Id == itemModel.ClientId
                localField: 'Item' // clientModel.Item == itemModel.filter({ ClientId: clientModel.Id })[0]
            }
        }
    }
});
Raúl
@raulromanp
Sep 23 2015 15:59
This message was deleted
This message was deleted
Raúl
@raulromanp
Sep 23 2015 18:16

Hi. I have a 'DSSqlAdapter' and I use node-sqlite3, in a node-webkit environment. Before this, I used localstorageAdapter and all ran well, writing and reading localstorage. NOW, I changed to DSSqlAdapter with sqlite3 and I don't know how to connect DSSqlAdapter with a 'node-sqlite3' instance. The config code is:

    var adapter = new DSSqlAdapter({
        client: 'sqlite3',
        connection: {
            filename: "./mydb.sqlite"
        }
    });

    DS.registerAdapter('sql', adapter, { default: true });

But no errors and nothing seems to matter. Only the empty file "mwdb.sqlite" is created.

Tnx!

Robert P
@robertdp
Sep 23 2015 22:08
@raulromanp So you've set up your models, but they're not working with the SQL adapter? Have you created the tables, and are your queries promises (findAll().catch(...) etc.) returning an error?
Robert P
@robertdp
Sep 23 2015 23:11
You can also try adding debug: true to your adapter config, but this is really for debugging queries and such.