mirror of
https://github.com/thinkjs/thinkjs.git
synced 2026-01-25 14:42:47 +00:00
update
This commit is contained in:
parent
266fe991e1
commit
eff511858e
@ -367,6 +367,14 @@ module.exports = Model(function(){
|
||||
return data;
|
||||
})
|
||||
},
|
||||
/**
|
||||
* 一对一提交
|
||||
* @param {[type]} data [description]
|
||||
* @param {[type]} value [description]
|
||||
* @param {[type]} mapOptions [description]
|
||||
* @param {[type]} parsedOptions [description]
|
||||
* @return {[type]} [description]
|
||||
*/
|
||||
_postHasOneRelation: function(data, value, mapOptions, parsedOptions){
|
||||
var promise = null;
|
||||
var self = this;
|
||||
@ -392,24 +400,41 @@ module.exports = Model(function(){
|
||||
_postBelongsToRelation: function(data, value, mapOptions, parsedOptions){
|
||||
return data;
|
||||
},
|
||||
/**
|
||||
* 一对多提交
|
||||
* @param {[type]} data [description]
|
||||
* @param {[type]} value [description]
|
||||
* @param {[type]} mapOptions [description]
|
||||
* @param {[type]} parsedOptions [description]
|
||||
* @return {[type]} [description]
|
||||
*/
|
||||
_postHasManyRelation: function(data, value, mapOptions, parsedOptions){
|
||||
|
||||
},
|
||||
/**
|
||||
* 多对多提交
|
||||
* @param Object data [description]
|
||||
* @param object value [description]
|
||||
* @param {[type]} mapOptions [description]
|
||||
* @param {[type]} parsedOptions [description]
|
||||
* @return {[type]} [description]
|
||||
*/
|
||||
_postManyToManyRelation: function(data, value, mapOptions, parsedOptions){
|
||||
var self = this;
|
||||
var promise = mapOptions.model.promise;
|
||||
var rfKey = value.rfKey || (mapOptions.model.getModelName().toLowerCase() + "_id");
|
||||
var relationTable = value.rTable || self.getRelationTableName(mapOptions.model);
|
||||
var model = mapOptions.model;
|
||||
var promise = model.promise;
|
||||
var rfKey = value.rfKey || (model.getModelName().toLowerCase() + "_id");
|
||||
var relationTable = value.rTable || self.getRelationTableName(model);
|
||||
var where;
|
||||
var type = mapOptions.type;
|
||||
var relationModel = self.getRelationModel(mapOptions.model);
|
||||
var mapData = mapOptions.mapData;
|
||||
var relationModel = self.getRelationModel(model);
|
||||
if (type === DELETE || type === UPDATE) {
|
||||
where = getObject(mapOptions.mapfKey, data[mapOptions.mapKey]);
|
||||
promise = promise.then(function(){
|
||||
return relationModel.where(where).delete();
|
||||
})
|
||||
};
|
||||
var mapData = mapOptions.mapData;
|
||||
if (type === ADD || type === UPDATE) {
|
||||
promise = promise.then(function(){
|
||||
if (!isArray(mapData)) {
|
||||
@ -426,11 +451,11 @@ module.exports = Model(function(){
|
||||
});
|
||||
return relationModel.addAll(postData);
|
||||
}else{ //实体数据
|
||||
var unqiueField = mapOptions.model.getUniqueField(firstItem);
|
||||
var unqiueField = model.getUniqueField(firstItem);
|
||||
if (!unqiueField) {
|
||||
return getPromise(mapOptions.model.getTableName() + " table has no unqiue field", true);
|
||||
return getPromise(model.getTableName() + " table has no unqiue field", true);
|
||||
};
|
||||
return self._getRalationAddIds(mapData, mapOptions.model, unqiueField).then(function(ids){
|
||||
return self._getRalationAddIds(mapData, model, unqiueField).then(function(ids){
|
||||
var postData = ids.map(function(id){
|
||||
var key = [mapOptions.mapfKey, rfKey];
|
||||
var val = [data[mapOptions.mapKey], id];
|
||||
@ -459,7 +484,7 @@ module.exports = Model(function(){
|
||||
return true;
|
||||
};
|
||||
var where = getObject(unqiueField, value);
|
||||
var promise = model.where(where).find().then(function(data){
|
||||
var promise = model.where(where).field(model.getPk()).find().then(function(data){
|
||||
if (isEmpty(data)) {
|
||||
return model.add(item).then(function(insertId){
|
||||
ids.push(insertId);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user