I would like to make a relation between two models User
and Task
using backbone-relational.
I would like for each Task
to get the User
model.
The relation between the two model is the following:
taskModel.creator_id = userModel.id
Here is my code (1) (2)
The issue is the following (3):
When I try to fetch the models of task I get for the attributes.user
the null value.
(1)
// TaskModel
var Task = Backbone.RelationalModel.extend({
relations: [
{
type: 'HasOne',
key: 'user',
relatedModel: User
}
],
urlRoot: 'url_get_tasks'
});
(2)
// UserModel
var User = Backbone.RelationalModel.extend({
urlRoot: "url_get_users"
});
(3)
user = new User();
user.fetch();
console.log(user.attributes); // {id: 1, .....}
task = new Task();
task.fetch();
console.log(task.attributes); // {id: 12, creator_id: 1, user: null} ???
Why the task.attributes.user
have the null
value?