From fdb142ecbf645612a3193868e5817b8c060c1e4b Mon Sep 17 00:00:00 2001 From: AJ ONeal Date: Wed, 21 Oct 2015 07:31:18 +0000 Subject: [PATCH] ignore some relationship fields on save --- lib/dbwrap.js | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/lib/dbwrap.js b/lib/dbwrap.js index 520d722..c7ab8da 100644 --- a/lib/dbwrap.js +++ b/lib/dbwrap.js @@ -240,6 +240,26 @@ function wrap(db, dir) { var sql; var vals = []; + ['hasOne', 'hasMany', 'hasAndBelongsToMany', 'belongsTo', 'belongsToMany'].forEach(function (relname) { + var rels = opts[relname]; + + if (!rels) { + return; + } + + if (!Array.isArray(rels)) { + rels = [rels]; + } + + // don't save relationships + rels.forEach(function (colname) { + delete data[colname]; + delete data[camelCase(colname)]; + // TODO placehold relationships on find / get? + // data[camelCase(colname)] = null; + }); + }); + (opts.indices || []).forEach(function (col) { if ('string' === typeof col) { col = { name: col, type: 'TEXT' };