当前位置: 首页>>代码示例>>PHP>>正文


PHP Jelly::insert方法代码示例

本文整理汇总了PHP中Jelly::insert方法的典型用法代码示例。如果您正苦于以下问题:PHP Jelly::insert方法的具体用法?PHP Jelly::insert怎么用?PHP Jelly::insert使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Jelly的用法示例。


在下文中一共展示了Jelly::insert方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: save

 /**
  * Implementation for Jelly_Field_Behavior_Saveable.
  *
  * @param   Jelly  $model
  * @param   mixed  $value
  * @return  void
  */
 public function save($model, $value, $loaded)
 {
     // Find all current records so that we can calculate what's changed
     $in = $loaded ? $this->_in($model, true) : array();
     // Find old relationships that must be deleted
     if ($old = array_diff($in, (array) $value)) {
         Jelly::delete($this->through['model'])->where($this->through['columns'][0], '=', $model->id())->where($this->through['columns'][1], 'IN', $old)->execute(Jelly::meta($model)->db());
     }
     // Find new relationships that must be inserted
     if (!empty($value) && ($new = array_diff((array) $value, $in))) {
         foreach ($new as $new_id) {
             if (!is_null($new_id)) {
                 Jelly::insert($this->through['model'])->columns($this->through['columns'])->values(array($model->id(), $new_id))->execute(Jelly::meta($model)->db());
             }
         }
     }
 }
开发者ID:netbiel,项目名称:core,代码行数:24,代码来源:manytomany.php

示例2: save

 /**
  * Implementation for Jelly_Field_Behavior_Saveable.
  *
  * @param   Jelly  $model
  * @param   mixed  $value
  * @return  void
  */
 public function save($model, $value, $loaded)
 {
     // Find all current records so that we can calculate what's changed
     $in = $loaded ? $this->_in($model, TRUE) : array();
     // Find old relationships that must be deleted
     if ($old = array_diff($in, (array) $value)) {
         Jelly::delete($this->through['model'])->where($this->through['columns'][0], '=', $model->id())->where($this->through['columns'][1], 'IN', $old)->execute(Jelly::meta($model)->db());
     }
     // Find new relationships that must be inserted
     if ($new = array_diff((array) $value, $in)) {
         foreach ($new as $new_id) {
             // Not sure why an array with NULL as the first value was coming through when you didn't submit anything
             // on the manytomany relationship but this avoids the problem for now...
             if ($new_id == NULL) {
                 continue;
             }
             /*
             				if (class_exists(Jelly::class_name($this->through['model']))) {
             					Jelly::factory(
             						$this->through['model'],
             						array(
             							$this->through['columns'][0] => $model->id(),
             							$this->through['columns'][1] => $new_id
             						)
             					)->save();
             				} else {
             */
             Jelly::insert($this->through['model'])->columns($this->through['columns'])->values(array($model->id(), $new_id))->execute(Jelly::meta($model)->db());
             //}
         }
     }
 }
开发者ID:vitch,项目名称:kohana-jelly,代码行数:39,代码来源:manytomany.php

示例3: save

 /**
  * Creates or updates the current record.
  *
  * If $key is passed, the record will be assumed to exist
  * and an update will be executed, even if the model isn't loaded().
  *
  * @param   mixed  $key
  * @return  $this
  **/
 public function save($key = NULL)
 {
     // Determine whether or not we're updating
     $data = ($this->_loaded or $key) ? $this->_changed : $this->_changed + $this->_original;
     if (!is_null($key)) {
         // There are no rules for this since it is a meta alias and not an actual field
         // but adding it allows us to check for uniqueness when lazy saving
         $data[':unique_key'] = $key;
     }
     // Set the key to our id if it isn't set
     if ($this->_loaded) {
         $key = $this->_original[$this->_meta->primary_key()];
     }
     // Run validation
     $data = $this->validate($data);
     // These will be processed later
     $values = $relations = array();
     // Iterate through all fields in original incase any unchanged fields
     // have save() behavior like timestamp updating...
     foreach ($this->_changed + $this->_original as $column => $value) {
         // Filters may have been applied to data, so we should use that value
         if (array_key_exists($column, $data)) {
             $value = $data[$column];
         }
         $field = $this->_meta->fields($column);
         // Only save in_db values
         if ($field->in_db) {
             // See if field wants to alter the value on save()
             $value = $field->save($this, $value, (bool) $key);
             if ($value !== $this->_original[$column]) {
                 // Value has changed (or has been changed by field:save())
                 $values[$field->name] = $value;
             } else {
                 // Insert defaults
                 if (!$key and !$this->changed($field->name) and !$field->primary) {
                     $values[$field->name] = $field->default;
                 }
             }
         } elseif ($this->changed($column) and $field instanceof Jelly_Field_Behavior_Saveable) {
             $relations[$column] = $value;
         }
     }
     // If we have a key, we're updating
     if ($key) {
         // Do we even have to update anything in the row?
         if ($values) {
             Jelly::update($this)->where(':unique_key', '=', $key)->set($values)->execute();
         }
     } else {
         list($id) = Jelly::insert($this)->columns(array_keys($values))->values(array_values($values))->execute();
         // Gotta make sure to set this
         $values[$this->_meta->primary_key()] = $id;
     }
     // Set the changed data back as original
     $this->_original = array_merge($this->_original, $this->_changed, $values);
     // We're good!
     $this->_loaded = $this->_saved = TRUE;
     $this->_retrieved = $this->_changed = array();
     // Save the relations
     foreach ($relations as $column => $value) {
         $this->_meta->fields($column)->save($this, $value, (bool) $key);
     }
     return $this;
 }
开发者ID:jerfowler,项目名称:kohana-jelly,代码行数:73,代码来源:core.php


注:本文中的Jelly::insert方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。