Bookshelf.js通过关系在hasMany上创建模型

时间:2015-09-10 02:11:34

标签: mysql bookshelf.js

以下是我的关系:

    days: function() {
        return this.hasMany('Day').through('Schedule');
    }

这是我的代码:

                var payload = _.extend(request.payload, {
                    create_user: request.auth.credentials.id,
                    update_user: request.auth.credentials.id
                });
                var currentProject = request.app.currentProject();

                return currentProject.then(function(project) {
                    return project.days().create(payload);
                }).then(function(model) {
                    return reply(model).code(201);
                }).catch(function(err) {
                    return reply(Boom.wrap(err));
                });

我收到了堆栈的MySQL错误:Error: ER_NO_REFERENCED_ROW_2: Cannot add or update a child row: a foreign key constraint fails (my_db.day, CONSTRAINT fk_day_schedule FOREIGN KEY (schedule_id) REFERENCES schedule (id) ON DELETE CASCADE ON UPDATE CASCADE)

0 个答案:

没有答案