Adds new record to database
@param \org\majkel\dbase\Record|\Traversable|array $data
@return integer index of new record
@throws Exception
166843
public function insert($data) {
        if ($data instanceof Record) {
            $data = clone $data;
        } else {
            $data = new Record(Utils::toArray($data));
        }
        return $this->getFormat()->insert($data);
    }
512657
public function getNew($data = [])
    {
        $pk = $this->getPrimaryKey();
        if (is_string($pk) && isset($data[$pk]) && $this->getRegistry()->has($data[$pk])) {
            $return = $this->getRegistry()->get($data[$pk]);
            $return->writeData($data);
            $return->writeDBData($data);

            return $return;
        }

        $record = $this->getNewRecordFromDB($data);

        return $record;
    }
302208
public static function insertOne(array $data)
    {
        $db = static::getDb();
    
        $db->insert(
            (new self())->getSource(),
            array_values($data),
            array_keys($data)
        );

        return $db->lastInsertId();
    }
146838
public function update($data, $id) {

		$bean = \R::findOne( $this->type, ' id = :id ', [ ':id' => $id ] );
		if ( !$bean ) {
			throw new \Exception('This '.$this->type.' does not exist.');
		}
		return $this->set($data, $bean);

	}
1330880
public function createFrom($data)
    {
        if ($data instanceof RecordList) {
            return $this->createMultiple($data);
        }
        return null == $data ? null : $this->createSingle($data);
    }
459172
public function create($data) {

		// Create
		$bean = $this->universalCreate();

		// Catch exception, because bean might already have been created by property method.
		try {
			return $this->set($data, $bean);
		} catch (Exception $e) {
			// Delete bean
			$this->delete($bean->id);
			throw new \Exception( $e->getMessage() );
		}

	}
1212550
public static function addGraph($data)
    {
        self::registerView();
        
        if (is_scalar($data)) {
            throw new Exception("Data must be either an array or an object of type luya\web\jsonld\BaseThing.");
        }
        
        Yii::$app->view->params['@context'] = 'https://schema.org';
        Yii::$app->view->params['@graph'][] = $data;
        
        return $data;
    }
505333
public function insert($data)
    {
        $db = $this->load();
        $db[] = $data;
        return $this->rewrite($db);
    }
796243
public function save($data=null)
    {
        if ( is_null($data)) {
            throw new \Exception('There is no data to save.');
        }

        $filter = array();
        if (isset($data['id'])) {
            $filter['id'] = $data['id'];
        }

        try {

            // check if exists record
            $entity = $this->getEntity($filter);
            if (!empty($filter['id']) && empty($entity)) {
                throw new \Exception("Role not found.");
            }
            $entity->setActive($data['active']);
            $entity->setName($data['name']);

            $_id = $entity->getId();
            if (isset($_id) && ($_id > 0)) {
                $this->_em->merge($entity);
            } else {
                $this->_em->persist($entity);
            }
            $this->_em->flush();
            $_id = $entity->getId();
        } catch (\Exception $e){
            \error_log($e->getMessage());
            throw new \Exception($e->getMessage());
        }
        return $_id;
    }
511278
public function addDataArray(array $data)
    {
        $this->data = $data;
        $this->pager->setTotalRows(\count($this->data));

        return $this;
    }
1346732
public static function insert($data)
    {
        $self  = self::getInstance();
        $table = $self->table_name;

        if (isset($data[0])) {
            $make      = $self->makeMultipleInsert($table, $data);
            $statement = $make[0];
            $value     = $make[1];
        } else {
            $newData    = $self->makeInsertParameter($data);
            $column     = implode(",", array_keys($data));
            $paramValue = implode(",", array_keys($newData));
            $statement  = "INSERT INTO {$table} ({$column}) VALUES({$paramValue});";
            $value      = $newData;
        }

        $execute   = $self->exec($statement, $value);

        return $execute;
    }
1131829
public function add($data = [])
    {
        $insertId = $this->db->insert($data)->into($this->table)->execute(FALSE);

        return $insertId;
    }
537941
public function add($records/*...$records*/)
    {
        if (!$this->owner->isPersisted()) {
            throw new Exception\RuntimeException(
                # TODO: terminar mensaje:
                # ...adding children to its $type association
                "Owner record must be persisted before adding children"
            );
        }
        
        $this->load();
        
        if (!is_array($records)) {
            $records = func_get_args();
        }
        
        if (!$records) {
            return true;
        }
        
        $className = get_class(reset($records));
        
        return $className::transaction(function() use ($records, $className) {
            
            $idsForUpdate = [];
            
            foreach ($records as $record) {
                if ($record->hasChanged()) {
                    if (!$record->updateAttribute($this->foreignKey, $this->owner->id())) {
                        # If a record won't save, cancel the whole process.
                        return false;
                    }
                } else {
                    $idsForUpdate[] = $record->id();
                }
            }
            
            if ($idsForUpdate) {
                $className::connection()
                    ->table($className::tableName())
                    ->where([$className::primaryKey() => $idsForUpdate])
                    ->update([$this->foreignKey => $this->owner->id()]);
            }
            
            $this->records->merge($records);
        });
    }
982263
public function addColumn($data)
    {
        if ($data instanceof Column) {
            $column = $data;
            $this->indexColumns[] = $column->getName();
            if ($column->getSize()) {
                $this->indexColumnSizes[$column->getName()] = $column->getSize();
            }
        } else {
            $attrib = $data;
            $name = $attrib["name"];
            $this->indexColumns[] = $name;
            if (isset($attrib["size"])) {
                $this->indexColumnSizes[$name] = $attrib["size"];
            }
        }
    }
918245
public function save($data=array())
    {

		if (empty($data)) {
			throw new \Exception( "User data is missing" );
		}
        $data = (object) $data;

		if ((!isset($data->email) || empty($data->email))) {
			throw new \Exception( "Email is required" );
		}
		if ((!isset($data->password) || empty($data->password)) && !isset($data->id)) {
			throw new \Exception( "Password is required" );
		}

		$new  = false;
		if (isset($data->id)) {
			$entity = $this->getById($data->id);
		} else {
			$entity = new entity();
			$new    = true;
		}
		if (isset($data->name)) {
			$entity->setName($data->name);
		}
		if (isset($data->email)) {
			$entity->setEmail($data->email);
		}
		if (isset($data->password)) {
			$entity->setPassword($this->getSalted($data->password));
		} elseif (isset($data->new_password)){
			$entity->setPassword($this->getSalted($data->new_password));
		}
		if (empty($data->role)) {
			$data->role = $this->_getDefaultRole();
		}
		$entity->setRole($data->role);
		if (isset($data->gateway_customer_id)) {
			$entity->setGatewayCustomerId($data->gateway_customer_id);
		}

		if ($new) {
			$this->_em->persist($entity);
		} else {
			$this->_em->merge($entity);
		}

		// Save the entity
		try {
			$eventType = $new ? Log::EVENT_CREATE : Log::EVENT_UPDATE;
			if(isset($data->new_password)){
				$eventType = Log::EVENT_PASSWORD;
				unset($data->new_password);
			}
			unset($data->password);

			$this->createUserEventLog($eventType, $data);
			$this->_em->flush();
			$this->setEntity($entity);

			return $entity->getId();

		} catch ( \Doctrine\DBAL\Exception\UniqueConstraintViolationException $e ) {
			// \Erdiko::log(\Psr\Log\LogLevel::INFO, 'UniqueConstraintViolationException caught: '.$e->getMessage());
			throw new \Exception( "Can not create user with duplicate email" );
		}

		return null;
	}
760197
protected function createUserInstance($data)
    {
        $config = app('scaffold.config');

        if (!$model = $this->fetchModel($config)) {
            throw new Exception('Could not find a model to create user.');
        }

        try {
            $model::unguard();

            return (new $model())->create($this->dataWithId($data));
        } catch (Exception $e) {
            return (new $model())->create($data);
        }
    }
139619
public function add_data(array $data)
	{
		$ar = \func_get_args();
		foreach ( $ar as $d ){
			if ( \is_array($d) ){
				$this->data = $this->has_data() ? array_merge($this->data,$d) : $d;
			}
		}
		return $this;
	}