mardi 26 mai 2015

Structuring ember data without making an additional model

I'm building an app where users can take todos. When they take tasks, I want to save them as "helpers" under the todo model.

Is there a way to do this without creating a separate model for helpers? It would be ideal to save helpers as user.helper.

I don't want to just save users as users under the todo model, because I already save the todo creator in todo.user.

Thanks!

Todo.js:

countMe: function(id) {

            var user = this.controllerFor('application').get('model');

            var todo = this.store.createRecord('todo', {
                helper: user,
            });

            this.store.find('todo', id).then(function(todo) {
                helper.get('todos').addObject(todo);
                helper.save();
            });

        },

Todo.js - model:

export default DS.Model.extend({
    title: DS.attr('string'),
    isCompleted: DS.attr('boolean', {defaultValue: false}),

    list: DS.belongsTo('list', {async: true}),
    user: DS.belongsTo('user', {async: true}),

    comment: DS.hasMany('comment', {async: true}),
    helper: DS.hasMany('helper', {async: true}),
});

User.js:

export default DS.Model.extend({
    displayName: DS.attr('string'),
    email: DS.attr('string'),

    list: DS.hasMany('list', {async: true}),
    todo: DS.hasMany('todo', {async: true}),
    comment: DS.hasMany('comment', {async: true})
});




Aucun commentaire:

Enregistrer un commentaire