Пример #1
0
 function insert($ignore = -1)
 {
     $this->call_action("insert_before", $this);
     $this->Validate('insert');
     if ($ignore instanceof InsertBuffer) {
         $ignore->add($this);
         return;
     }
     //Build & Do SQL
     $data = $this->toSQL();
     foreach ($data as $k => $v) {
         if ($v === null) {
             unset($data[$k]);
         }
     }
     //Validate required fields
     $missing = $this->orm->validation->what_is_missing($data);
     if ($missing !== null) {
         throw new ValidationException('Missing field ' . $missing);
     }
     $id = \Radical\DB::Insert($this->orm->tableInfo['name'], $data, $ignore ? $ignore : null);
     if ($id === false) {
         throw new \RuntimeException('Unable to insert into table ' . $this->orm->tableInfo['name']);
     }
     foreach ($data as $k => $v) {
         $this->_store[$this->orm->mappings[$k]] = $v;
     }
     //Is an auto incrememnt returned?
     if ($id) {
         $autoInc = $this->orm->autoIncrement;
         //Is auto increment column
         if ($autoInc) {
             //Set auto increment column
             $this->{$autoInc} = $id;
             //Set store
             $this->_store[$autoInc] = $id;
         }
     }
     $this->call_action("insert_after", $this);
 }