Giter Site home page Giter Site logo

Comments (7)

jfbenckhuijsen avatar jfbenckhuijsen commented on May 25, 2024

Ok, been experimenting a bit. So far I've come up with this:

return entities.map((entity) => { delete entity.id; return new MyModelClass(entity, entity[gstore.KEY]); });

The delete entity.id seems needed as the query result includes this value, whereas the schema doesn't define this as a valid property. I am seeing some weird behaviour though, where saving the returned entity seems to result in new entities being added, instead of the existing one being updated.

from gstore-node.

sebelga avatar sebelga commented on May 25, 2024

That might be something nice to add as an option parameter to query.
Until then you guessed right that you need to delete the id first. Then, try something like this in your map (untested):

return entities.map((entity) => {
    delete entity.id;
    return MyModelClass.__model(entity, null, null, null, entity[gstore.KEY]);
});

Tell me if it worked.

from gstore-node.

jfbenckhuijsen avatar jfbenckhuijsen commented on May 25, 2024

Doesn't seem to give the desired effect. When debugging, in model.js:717, var entity is constructed. In the first case (i.e. after construction of the initial object), this.entityKey contains four fields:

  • kind: User
  • namespace: undefined
  • path: undefined
  • name : "[some uuid generated string]"

After executing a query, I call save again on the object constructed in the way described above. When I reenter model.js:717, this.entityKey does not have the name property.

from gstore-node.

jfbenckhuijsen avatar jfbenckhuijsen commented on May 25, 2024

Been debugging this on the fork I created, have the feeling the fromDatastore() function in datastore.js somehow does not copy the key.

from gstore-node.

sebelga avatar sebelga commented on May 25, 2024

Sorry I made a mistake. Inside the map function, its gstore.ds.KEY to access the Symbol for the entityKey. So try with:

return entities.map((entity) => {
    delete entity.id;
    return MyModelClass.__model(entity, null, null, null, entity[gstore.ds.KEY]);
});

It should work.

from gstore-node.

sebelga avatar sebelga commented on May 25, 2024

Did you have a chance to try the solution?

from gstore-node.

jfbenckhuijsen avatar jfbenckhuijsen commented on May 25, 2024

Yes. It worked. After I finished with the virtual properties pull request, I'll craft up a feature to have this in the library itself.

Verstuurd vanaf mijn iPhone

Op 8 nov. 2016 om 18:20 heeft Sébastien Loix [email protected] het volgende geschreven:

Did you have a chance to try the solution?


You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub, or mute the thread.

from gstore-node.

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.