Пример #1
0
 /**
  * Commit all deferred bindings to this model.
  */
 public function commitDeferred($sessionKey)
 {
     if (!strlen($sessionKey)) {
         return;
     }
     $bindings = DeferredBindingModel::where('master_type', get_class($this))->where('session_key', $sessionKey)->get();
     foreach ($bindings as $binding) {
         if (!($relationName = $binding->master_field)) {
             continue;
         }
         if (!$this->isDeferrable($relationName)) {
             continue;
         }
         /*
          * Find the slave model
          */
         $slaveClass = $binding->slave_type;
         $slaveModel = new $slaveClass();
         $slaveModel = $slaveModel->find($binding->slave_id);
         if (!$slaveModel) {
             continue;
         }
         /*
          * Bind/Unbind the relationship, save the related model with any
          * deferred bindings it might have and delete the binding action
          */
         $relationObj = $this->{$relationName}();
         if ($binding->is_bind) {
             $relationObj->add($slaveModel);
         } else {
             $relationObj->remove($slaveModel);
         }
         $binding->delete();
     }
 }