Create a new instance of the given model.

@param  array  $attributes
@param  bool  $exists
@return EmbedModel
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;
    }
704794
public function newPivot(array $attributes = [], $exists = false)
	{
		$pivot = new MorphPivot($this->parent, $attributes, $this->table, $exists);

		$pivot->setPivotKeys($this->foreignKey, $this->otherKey)
			  ->setMorphType($this->morphType)
			  ->setMorphClass($this->morphClass);

		return $pivot;
	}
827246
public function firstOrCreate( array $attributes )
	{
		if ( !is_null( $instance = $this->where( $attributes )->first() ) )
			return $instance;

		$instance = $this->model->newInstance( $attributes );

		$instance->save();

		return $instance;
	}
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();
    }
548253
public function make(array $attributes = [])
    {
        $instance = $this->related->newInstance($attributes);
        $this->setForeignAttributesForCreate($instance);
        return $instance;
    }
547103
public static function createOne(array $attributes)
    {
        return tap(new self($attributes), function (self $post) use ($attributes) {
            $post->save();

            $post->tags()->sync($attributes['tags']);

            $post->createSeo(
                static::extractSeoAttributes($attributes)
            );
        });
    }
623424
public function newPivot(array $attributes = [], $exists = false)
    {

        $using = $this->using;

        $pivot = $using ? $using::fromRawAttributes($this->parent, $attributes, $this->table, $exists)
                        : new MorphPivot($attributes, $this->parent, $this->table, $exists);

        $pivot->setPivotKeys($this->foreignKey, $this->relatedKey)
              ->setMorphType($this->morphType)
              ->setMorphClass($this->morphClass);

        return $pivot;
    }
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;
        }
    }
1181910
public function newPivot(array $attributes = [], $exists = false)
	{
		$pivot = $this->related->newPivot($this->parent, $attributes, $this->table, $exists);

		return $pivot->setPivotKeys($this->foreignKey, $this->otherKey);
	}
445386
public function forceCreate(array $attributes)
    {
        return $this->model->unguarded(function () use ($attributes) {
            return $this->newModelInstance()->create($attributes);
        });
    }
1013548
public static function fromAttributes(Model $parent, $attributes, $table, $exists = false)
    {
        $instance = new static;

        $instance->timestamps = $instance->hasTimestampAttributes($attributes);

        // The pivot model is a "dynamic" model since we will set the tables dynamically
        // for the instance. This allows it work for any intermediate tables for the
        // many to many relationship that are defined by this developer's classes.
        $instance->setConnection($parent->getConnectionName())
            ->setTable($table)
            ->forceFill($attributes)
            ->syncOriginal();

        // We store off the parent instance so we will access the timestamp column names
        // for the model, since the pivot model timestamps aren't easily configurable
        // from the developer's point of view. We can use the parents to get these.
        $instance->pivotParent = $parent;

        $instance->exists = $exists;

        return $instance;
    }
653230
public function add(array $attributes = array())
    {
        if (!$this->contains($attributes)) {
            $this->model->getModel()->newInstance($attributes)->save();
            $this->cache->forget($this->cacheKey);
        }
        return $this;
    }
621878
public static function factory($attributes)
    {
        $instance = new self();
        $values = array_values($attributes);
        $instance->_initialize(array_shift($values));
        return $instance;
    }
854845
public static function fromRawAttributes(Model $parent, $attributes, $table, $exists = false)
    {
        $instance = static::fromAttributes($parent, [], $table, $exists);

        $instance->timestamps = $instance->hasTimestampAttributes($attributes);

        $instance->setRawAttributes($attributes, true);

        return $instance;
    }
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);
    }
1200608
public static function create(array $attributes)
    {
        $model = new PaymentTransaction;
        $model->attributes = $attributes;
        $model->userIdentifier = isset($attributes['userIdentifier']) ? $attributes['userIdentifier'] : Yii::app()->user->id;
        $model->locale = isset($attributes['locale']) ? $attributes['locale'] : Yii::app()->language;
        if (!$model->save()) {
            throw new CException('Failed to save payment transaction.');
        }
        return $model;
    }
623679
protected function createAndFill(array $attributes)
    {
        $entityClass = static::makes();
        $entity = new $entityClass;

        foreach($attributes as $attribute => $value) {
            $entity->$attribute = $value;
        }

        return $entity;
    }