Schema examples please
I like Total.js, but ended not yet fully understand the operation of the "Schema" for example the difference between $save and $workflow. I have already read the documentation :)
If there is any example (CRUD) would be great.
Thank you very much.
+1 👍 There need for this, a simple TODO app would be great..
Hi, the best SCHEMA example is https://github.com/totaljs/cms Have a look at ./controllers/manager.js which uses multiple schemas then check ./models/ folder for how the schemas are defined. It's clearly much better example then any TODO app could ever be.
@carlos-duran the difference between $save and $workflow
As the name $save suggest it servers the purpose of saving document into DB, whereas $workflow can do anything you want, which means you can create a workflow for saving data too, so in a way you can say $save is alternative for $workflow('save') . To give You an example imagine following situation. A user fills in a register form on Your page and submits it then on the server You need to check if the user's email already exists in DB and if not then save the user data and send him an email confirmation of registration. Now in the code it would look like this:
//controller
F.route('/register', json_register, ['post', '*User']);
function json_register(){
var self = this;
self.body.$async(self.callback(), 1).$workflow('check.email').$save().$workflow('send.confirmation');
}
This gives you clear view of what's going on in the code. Have a look at the cms I mentioned above. It's really great example.
Thank you for the answer. I will see the cms source code :+1:
Have a good day.