查找相关的数据, 更新或者插入
@param {object} source source model
@param {string} model target model
@param {object|array} args 要生成的参数
@param {any} t 事务标志
@return {*}
@this model
540362
async function findOrUpdateOrCreate (source, model, args, t) {
  let association = this.associations[model] || this.associations[pluralize.plural(model)]

  switch (association.associationType) {
    case 'HasOne':
      await one2one.call(this, source, model, args, t)
      break
    case 'HasMany':
      await one2many.call(this, source, model, args, t)
      break
    case 'BelongsToMany':
      await many2many.call(this, source, model, args, t)
      break
    default:
      throw new Error(`当前关系: ${association}, 数据不一致`)
  }
}
810362
function (source, opts, cb) {
        var callback,
            options;

        if (arguments.length === 2) {
            options = defaults();
            callback = opts;
        } else {
            options = defaults(opts);
            callback = cb;
        }

        try {
            source = api.clean(source);
            callback(null, api.insert(source, getToc(source, options)));
        } catch (err) {
            callback(err, null);
        }
    }
46156
def get_source_handler(self, model, source):
        
        if isinstance(source, Column):
            return source

        # Generate a generic handler for the source
        modelfield = resolve_orm_path(model, source)
        column_class = get_column_for_modelfield(modelfield)
        return column_class()
1179320
function update(model) {
  var params = arguments.length <= 1 || arguments[1] === undefined ? {} : arguments[1];

  if (!model) {
    throw new Error('No model provided.');
  }
  var currentState = model.toJSON({ shallow: true });
  currentState.id = String(currentState.id);

  return _destructure2['default'](model, params).then(function (destructured) {
    var attributes = destructured.attributes;
    var relations = destructured.relations;

    return _transact2['default'](model, function (transaction) {
      return model.save(attributes, {
        patch: true,
        method: 'update',
        transacting: transaction
      }).tap(function (model) {
        return _relate2['default'](model, relations, 'update', transaction);
      }).then(function (model) {
        // if model didn't change, return null
        // model.previousAttributes() is broken.
        // https://github.com/tgriesser/bookshelf/issues/326
        var updatedState = model.toJSON({ shallow: true });
        updatedState.id = String(updatedState.id);
        return _lodash2['default'].isEqual(currentState, updatedState) ? null : model;
      });
    });
  });
}
347396
public EventBus emitAsync(String event, Object... args) {
        return _emitWithOnceBus(eventContextAsync(event, args));
    }
1331178
def source_filter(method_name, *args, **kwargs):
    

    def source_filter(value, context, **_params):
        method = getattr(context["model"].source, method_name)
        return _filter(method, value, args, kwargs)

    return source_filter
721736
public EventBus emitSync(EventObject event, Object... args) {
        return _emitWithOnceBus(eventContextSync(event, args));
    }
544113
public EventBus emitAsync(ActEvent event, Object... args) {
        return _emitWithOnceBus(eventContextAsync(event, args));
    }
923180
function generateListHandler(model, options, logger) {
  const Log = logger.bind()
  options = options || {}

  return async function(request, h) {
    try {
      Log.log(
        'params(%s), query(%s), payload(%s)',
        JSON.stringify(request.params),
        JSON.stringify(request.query),
        JSON.stringify(request.payload)
      )

      let result = await handlerHelper.listHandler(model, request, Log)
      delete result.pageData
      return h.response(result).code(200)
    } catch (err) {
      handleError(err, Log)
    }
  }
}
611337
def add_source_model(
            self, model, area_border='k-', border_width=1.0,
            point_marker='ks', point_size=2.0, overlay=False, min_depth=0.,
            max_depth=None, alpha=1.0):
        
        for source in model.sources:
            if isinstance(source, mtkAreaSource):
                self._plot_area_source(source, area_border, border_width)
            elif isinstance(source, mtkPointSource):
                self._plot_point_source(source, point_marker, point_size)
            elif isinstance(source, mtkComplexFaultSource):
                self._plot_complex_fault(source, area_border, border_width,
                                         min_depth, max_depth, alpha)
            elif isinstance(source, mtkSimpleFaultSource):
                self._plot_simple_fault(source, area_border, border_width)
            else:
                pass
        if not overlay:
            plt.show()
817684
function (args) {
  tgi.Model.call(this, args);
  this.modelType = "Actor";
  this.attributes.push(new tgi.Attribute('Name'));
  this.attributes.push(new tgi.Attribute('Born', 'Number'));
  this.attributes.push(new tgi.Attribute({name:'Today', type:'Date', hidden:'*'}));
  this.attributes.push(new tgi.Attribute('Sex'));
  this.attributes.push(new tgi.Attribute('Joystick','Boolean'));
}
922996
public EventBus emit(ActEvent event, Object... args) {
        return _emitWithOnceBus(eventContext(event, args));
    }
459143
public EventBus emitSync(ActEvent event, Object... args) {
        return _emitWithOnceBus(eventContextSync(event, args));
    }
232357
def _add_event_source(awsclient, evt_source, lambda_arn):
    
    event_source_obj = _get_event_source_obj(awsclient, evt_source)

    # (where zappa goes like remove, add)
    # we go with update and add like this:
    if event_source_obj.exists(lambda_arn):
        event_source_obj.update(lambda_arn)
    else:
        event_source_obj.add(lambda_arn)
116739
function (event) {
			var sPath = event.getSource().getBindingContext("treeModel").getPath(),
				sourceObject = this.treeTable.getBinding().getModel().getProperty(sPath),
				libs = this.model.getProperty("/libraries");

			libs.forEach(function (lib, libIndex) {
				lib.rules.forEach(function (rule) {
					if (rule.id === sourceObject.id) {
						sourceObject.check = rule.check;
					}
				});
			});
			return sourceObject;
		}
767041
def create_new_model(model, from_method)
      if model.is_a?(Model)
        if model.buffer?
          fail "The #{from_method} does not take a buffer.  Call .save! on buffer's to persist them."
        end

        # Set the new path and the persistor.
        model.options = @options.merge(parent: self, path: @options[:path] + [:[]])
      else
        model = wrap_values([model]).first
      end


      if model.is_a?(Model)
        promise = model.can_create?.then do |can_create|
          unless can_create
            fail "permissions did not allow create for #{model.inspect}"
          end
        end.then do

          # Add it to the array and trigger any watches or on events.
          reactive_array_append(model)

          @persistor.added(model, @array.size - 1)
        end.then do
          nil.then do
            # Validate and save
            model.run_changed
          end.then do
            # Mark the model as not new
            model.instance_variable_set('@new', false)

            # Mark the model as loaded
            model.change_state_to(:loaded_state, :loaded)

          end.fail do |err|
            # remove from the collection because it failed to save on the server
            # we don't need to call delete on the server.
            index = @array.index(model)
            delete_at(index, true)

            # remove from the id list
            @persistor.try(:remove_tracking_id, model)

            # re-raise, err might not be an Error object, so we use a rejected promise to re-raise
            Promise.new.reject(err)
          end
        end
      else
        promise = nil.then do
          # Add it to the array and trigger any watches or on events.
          reactive_array_append(model)

          @persistor.added(model, @array.size - 1)
        end
      end

      promise = promise.then do
        # resolve the model
        model
      end

      # unwrap the promise if the persistor is synchronus.
      # This will return the value or raise the exception.
      promise = promise.unwrap unless @persistor.async?

      # return
      promise
    end
1058960
function (model) {
            this._super(arguments);
            var ctiKey = this.__ctiKey = model.__ctiKey;
            this.__ctiTables = model.__ctiTables.slice();
            this.__ctiModels = model.__ctiModels.slice();
            this.__ctiModels.push(this);
            this.__ctiTables.push(this.tableName);
            this.__ctiColumns = comb.merge({}, model.__ctiColumns);
            this.__ctiColumns[this.tableName] = this.columns;
            this.__ctiBaseModel = model.__ctiBaseModel;
            //copy over our schema
            var newSchema = comb.merge({}, this.__schema);
            var schemas = model.__ctiModels.map(
                function (m) {
                    return m.schema;
                }).reverse();
            schemas.forEach(function (s) {
                for (var i in s) {
                    newSchema[i] = s[i];
                }
            }, this);
            this._setSchema(newSchema);
            this._setDataset(model.dataset.join(this.tableName, this.primaryKey));
            this._setPrimaryKey(this.__ctiBaseModel.primaryKey);
            this.pre("save", function (next) {
                if (ctiKey) {
                    this[ctiKey] = this.tableName.toString();
                }
                next();
            });
        }