Comments (9)
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.
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.
I see. Without actually inserting the user in the datastore, I assume?
from fire.
Yes that's correct. It's just convenience....
from fire.
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.
Yes I agree that's more elegant.
from fire.
How's the reading going and did you see the latest features?
from fire.
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.
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)
- grunt build HOT 6
- nobase error when running client HOT 2
- Calculated properties HOT 2
- apps:create problem HOT 9
- I'm curious to hear why you aren't using the pg native bindings? HOT 3
- Error creating "schemas" relation when running 'grunt release' for multi-apps example HOT 4
- Different id name in model? HOT 3
- Error when attempting to run a new nodeonfire application HOT 4
- Minor Site issue, isometric example link on http://nodeonfire.org/examples is pointing to Multiple Apps example.
- Move migrations functionality to separate module HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from fire.