lib/plugins/inheritance.js
function () {
            var Self = this._static, ret;
            if (Self === Self.__ctiBaseModel) {
                ret = this._super(arguments);
            } else {
                var pk = this.primaryKey[0], tables = Self.__ctiTables, ctiColumns = Self.__ctiColumns, self = this,
                    isRestricted = Self.isRestrictedPrimaryKey, db = this.db;
                ret = asyncArray.forEach(tables,function (table, index) {
                    var cols = ctiColumns[table], insert = {}, val, i = -1, colLength = cols.length, c;
                    while (++i < colLength) {
                        c = cols[i];
                        if ((index !== 0 || (index === 0 && (!isRestricted || pk.indexOf(c) === -1))) && !comb.isUndefined(val = self[c])) {
                            insert[c] = val;
                        }
                    }
                    return db.from(table).insert(insert).chain(function (id) {
                        if (comb.isUndefined(self.primaryKeyValue) && !comb.isUndefined(id) && index === 0) {
                            self.__ignore = true;
                            //how to handle composite keys.
                            self[pk] = id;
                            self.__ignore = false;
                        }
                    });
                }, 1).chain(function () {
                        self.__isNew = false;
                        self.__isChanged = false;
                        return self._saveReload();
                    });
            }
            return ret.promise();
        }
function () {
            var Self = this._static, ret;
            if (Self === Self.__ctiBaseModel) {
                ret = this._super(arguments);
            } else {
                var pk = this.primaryKey[0], tables = Self.__ctiTables, ctiColumns = Self.__ctiColumns, self = this,
                    isRestricted = Self.isRestrictedPrimaryKey, db = this.db;
                ret = asyncArray.forEach(tables,function (table, index) {
                    var cols = ctiColumns[table], insert = {}, val, i = -1, colLength = cols.length, c;
                    while (++i < colLength) {
                        c = cols[i];
                        if ((index !== 0 || (index === 0 && (!isRestricted || pk.indexOf(c) === -1))) && !comb.isUndefined(val = self[c])) {
                            insert[c] = val;
                        }
                    }
                    return db.from(table).insert(insert).chain(function (id) {
                        if (comb.isUndefined(self.primaryKeyValue) && !comb.isUndefined(id) && index === 0) {
                            self.__ignore = true;
                            //how to handle composite keys.
                            self[pk] = id;
                            self.__ignore = false;
                        }
                    });
                }, 1).chain(function () {
                        self.__isNew = false;
                        self.__isChanged = false;
                        return self._saveReload();
                    });
            }
            return ret.promise();
        }
function ( ) { var Self = this . _static , ret ; if ( Self === Self . __ctiBaseModel ) { ret = this . _super ( arguments ) ; } else { var pk = this . primaryKey [ 0 ] , tables = Self . __ctiTables , ctiColumns = Self . __ctiColumns , self = this , isRestricted = Self . isRestrictedPrimaryKey , db = this . db ; ret = asyncArray . forEach ( tables , function ( table , index ) { var cols = ctiColumns [ table ] , insert = { } , val , i = - 1 , colLength = cols . length , c ; while ( ++ i < colLength ) { c = cols [ i ] ; if ( ( index !== 0 || ( index === 0 && ( ! isRestricted || pk . indexOf ( c ) === - 1 ) ) ) && ! comb . isUndefined ( val = self [ c ] ) ) { insert [ c ] = val ; } } return db . from ( table ) . insert ( insert ) . chain ( function ( id ) { if ( comb . isUndefined ( self . primaryKeyValue ) && ! comb . isUndefined ( id ) && index === 0 ) { self . __ignore = true ; //how to handle composite keys. self [ pk ] = id ; self . __ignore = false ; } } ) ; } , 1 ) . chain ( function ( ) { self . __isNew = false ; self . __isChanged = false ; return self . _saveReload ( ) ; } ) ; } return ret . promise ( ) ; }
Save each column according to the columns in each table
Save each column according to the columns in each table