I try to create a blog using Compound.js. I have two tables, "Category" and "Post", in each I have the date property, but when I generate the tables, I got a form with an input for the date property in each "new" view...
I wanna update the date propperty automatically in my controller when this is created.
How can I make?
My shema:
var Category = describe('Category', function () {
property('name', String);
property('date', Date);
set('restPath', pathTo.categories);
});
var Post = describe('Post', function () {
property('title', String);
property('content', String);
property('published', Boolean);
property('date', Date);
set('restPath', pathTo.posts);
});
Category.hasMany(Post, {as: 'posts', foreignKey: 'categoryId'});
My model:
module.exports = function (compound, Category) {
// define Category here
};
My controller:
action('new', function () {
this.title = 'New category';
this.category = new Category;
render();
});
action(function create() {
Category.create(req.body.Category, function (err, category) {
respondTo(function (format) {
format.json(function () {
if (err) {
send({code: 500, error: category && category.errors || err});
} else {
send({code: 200, data: category.toObject()});
}
});
format.html(function () {
if (err) {
flash('error', 'Category can not be created');
render('new', {
category: category,
title: 'New category'
});
} else {
flash('info', 'Category created');
redirect(path_to.categories);
}
});
});
});
});