Using bookshelfjs, I would like to add an entry to the connection table containing an extra column with a null value.
For example, the user table and account table will have an account connection table.
var Account = Bookshelf.Model.extend({
tableName: 'accounts'
});
var User = Bookshelf.Model.extend({
tableName: 'users',
accounts: function () {
return this.belongsToMany(Account);
}
});
The join table also has an NOT NULL order column.
CREATE TABLE accounts_users
(
account_id integer NOT NULL,
user_id integer NOT NULL,
"order" integer NOT NULL,
CONSTRAINT accounts_users_account_id_foreign FOREIGN KEY (account_id)
REFERENCES accounts (id) MATCH SIMPLE
ON UPDATE CASCADE ON DELETE CASCADE,
CONSTRAINT accounts_users_user_id_foreign FOREIGN KEY (user_id)
REFERENCES users (id) MATCH SIMPLE
ON UPDATE CASCADE ON DELETE CASCADE
)
Is it possible to attach an entry in Users to an entry in accounts and at the same time set the order value?
Each of them can be done separately using:
user.related("accounts").attach(<USER_ID>);
and
user.related("accounts").updatePivot({order: 1});
, NOT NULL. ? Knex.Raw, , , .