I'm trying to expand on the GeddyJS Todo tutorial from their site. I've added another model, Project, to the Todo project, and would like to set up a relationship between Todo and Project in a Todo-hasOne-Project manner.
Here's the code from my create controller method where I attempt to set the relationship up after the Todo item is saved:
todo.save(function(err, data) {
if(err) {
params.errors = err;
self.transfer('add');
} else {
geddy.model.Project.getProjectById(todo.parent, function(err, project) {
if(err) {
params.errors = err;
self.transfer('add');
}
else {
todo.setProject(project);
self.redirect({ controller: self.name });
}
});
}
});
I'm using a class method (getProjectById) that takes the todo's parent property (Project's id) to fetch the project from the db.
In my Todo class file, I have the hasOne relationship defined as follows:
this.hasOne('Project');
I keep getting compiler errors that read:
c:\Program Files (x86)\nodejs\node_modules\geddy\node_modules\model\lib\index.js:254
throw new Error('Item cannot have a hasOne/hasMany association ' +
^
Error: Item cannot have a hasOne/hasMany association if it is not yet saved..
Finding by-example documentation has proven difficult, so I thought I'd ask the strongest community on the web.
Anyone know what I'm missing?