Giter VIP home page Giter VIP logo

Comments (9)

martijndeh avatar martijndeh commented on June 24, 2024

You can create a new model instance by invoking the below. This also inserts the model in the datastore.

models.User.create({
    name: 'Arjan'
});

If you want to retrieve any existing model instances, you can use e.g.:

models.User.findOne({
    name: 'Arjan'
});

Is this what you mean?

from fire.

arjan123 avatar arjan123 commented on June 24, 2024

Almost,

I mean more like this

models.User.new().then(function(user)
{
});
to create a new User instance including default/initial values etc...
where user gives me f.e.

{
name: '',
username: '',
password: '',
isCompany: true, //initial value,
receiveNewsLetter: true,

etc....
}

from fire.

martijndeh avatar martijndeh commented on June 24, 2024

I see. Without actually inserting the user in the datastore, I assume?

from fire.

arjan123 avatar arjan123 commented on June 24, 2024

Yes that's correct. It's just convenience....

from fire.

martijndeh avatar martijndeh commented on June 24, 2024

Model#new should be fairly easy to implement. When accessing properties, some would be undefined though, as they are set through SQL statements (only after creating or selecting). I also feel it might introduce issues and confusion, as Model#new implies it's creating a new model instance and inserts it in the datastore, but it's actually just creating the instance.

A similar idea is something like:

var user = new models.User();
user.name = 'Arjan';
user.save();

What do you think of that?

from fire.

avandijk avatar avandijk commented on June 24, 2024

Yes I agree that's more elegant.

from fire.

martijndeh avatar martijndeh commented on June 24, 2024

How's the reading going and did you see the latest features?

from fire.

arjan123 avatar arjan123 commented on June 24, 2024

I like those new features. Especially sockets. I've to figure out the new sources yet.
You develop more quickly than I can read!!

I've also setup a test project to try some of the features.
I'll keep you informed about my test results....

thx

from fire.

martijndeh avatar martijndeh commented on June 24, 2024

In 0.41.0 we introduced a ModelInstance#new method. This creates a new model instance without persisting it to the datastore. When calling ModelInstance#save on the object it'll persist to the datastore.

The below creates a Pie instance and saves it to the datastore:

var pie = PieModel.new();
pie.type = 'Apple';
pie.save()

ModelInstance#new is isomorphic so it's available on both the front- and the back-end.

from fire.

Related Issues (11)

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.