build entity.

@access  public
@param   array   $attributes
@param   boolean $exists
@return  Entity
494037
public function build($attributes = array(), $exists = false)
    {
        $class = $this->getEntityClass();
        $entity = new $class($this, $attributes, $exists);
        return $entity;
    }
329796
public function create($attributes = array())
    {
        $entity = $this->build($attributes);

        // to SQL.
        $criteria = $this->criteria();
        $sql = $criteria->toInsertSQL($attributes);

        // query.
        $sth = $this->query($sql, $criteria->getParams(), Database::TARGET_MASTER);
        if ($sth->isSuccess()) {
            $entity->exists = true;
            $entity->setPrimaryValue($sth->lastInsertId());
            return $entity;
        }
    }
658809
public function newInstance($attributes = [], $exists = false)
    {
        $model = new static();
        $model->fill((array) $attributes, $exists);
        $model->syncOriginal();

        $model->exists = $exists;

        $model->setConnection($this->getConnectionName());

        return $model;
    }
1040212
public function create(array $attributes)
    {
        $entity = $this->getNew($attributes);

        if ($entity->save()) {
            $this->flushCache();

            return $entity;
        }

        return false;
    }
1327512
public function create(array $attributes)
	{
		$foreign = array(
			$this->getPlainForeignKey() => $this->getParentKey(),
		);

		// Here we will set the raw attributes to avoid hitting the "fill" method so
		// that we do not have to worry about a mass accessor rules blocking sets
		// on the models. Otherwise, some of these attributes will not get set.
		$instance = $this->related->newInstance();

		$instance->setRawAttributes(array_merge($attributes, $foreign));

		$instance->save();

		return $instance;
	}
1353077
public function updateOrCreate(array $attributes, array $values = [])
    {
        $instance = $this->firstOrNew($attributes);

        $instance->fill($values);

        $instance->save();

        return $instance;
    }
10906
private function prepareExists(array $exists)
    {
        if ($exists['sql'] instanceof SelectQuery) {
            [$sql, $params] = $exists['sql']->toSql();

            $exists['sql'] = $sql;

            $exists['params'] = $params;
        }

        return $exists;
    }
1213951
public function entry(array $attributes = [])
    {
        $model = $this->schema->entryModel();

        return (new $model($attributes, $this->query));
    }
560238
public function newModelInstance($attributes = [])
    {
        return $this->model->newInstance($attributes)->setConnection(
            $this->query->getConnection()
        );
    }
1062569
protected function makeInstance(array $attributes = [])
    {
        if (! isset($this->definitions[$this->class][$this->name])) {
            throw new InvalidArgumentException("Unable to locate factory with name [{$this->name}] [{$this->class}].");
        }

        $entityWrapper = $this->entityFactory->make($this->getMapper()->newInstance());

        $definition = call_user_func(
            $this->definitions[$this->class][$this->name], 
            $this->faker, $attributes);

        $entityWrapper->setEntityAttributes(array_merge($this->applyStates($definition, $attributes), $attributes));

        return $entityWrapper->unwrap();
    }
198571
public function create_new(array $attributes = array())
    {
        $instance = null;

        if (!$this->is_collection) {
            $instance = new self::$custom_collections[$this->name]();
        } else {
            $instance = new Collection(array('table_name' => $this->name));
        }

        $instance->fill($attributes);

        // Fill '_id' if it's provided and in a trusted context
        if (isset($attributes['_id']) && Context::isTrusted()) {
            $instance->_id = $attributes['_id'];
        }

        return $instance;
    }
316454
public function updateOrCreate(array $attributes, array $updateAttributes)
    {
        $model = $this->get($attributes);
        if (null === $model) {
            $model = $this->getModel()->create();
            $model->setIsNewRecord(true);
        }

        $model->setAttributes($updateAttributes);
        if ($model->save()) {
            return $model;
        }

        return false;
    }
63447
public function newFromBuilder($attributes = array())
    {
        $m = $this->mapData((array) $attributes)->newInstance(array(), true);
        $m->setRawAttributes((array) $attributes, true);
        return $m;
    }
413297
public function make(array $attributes=[])
    {
        $model = $this->getModel()->newInstance($attributes);
        $this->fire($this->event('make'), [$model]);
        return $model;
    }
917701
public static function create(array $attributes = [])
    {
        $attributes['password'] = bcrypt($attributes['password']);

        $user = new AppUser($attributes);
        $user->save();

        return $user;
    }
835315
public function create(array $attributes = [], array $properties = array())
    {
        // Here we will set the raw attributes to avoid hitting the "fill" method so
        // that we do not have to worry about a mass accessor rules blocking sets
        // on the models. Otherwise, some of these attributes will not get set.
        $instance = $this->related->newInstance($attributes);

        return $this->save($instance, $properties);
    }
772001
public function newInstance($attributes = [], $exists = false)
    {
        $model = new static($this->callbackGet, $this->callbackSet, $this->callbackUnset);
        $model->fill((array) $attributes);

        $this->id = array_key_exists('_id', $attributes) ? $attributes['_id'] : null;

        $model->exists = $exists;

        return $model;
    }