src/Leevel/Database/Ddd/Entity.php
protected function createReal(?array $fill = null): IEntity
    {
        $this->leevelFlushed = false;

        $this->parseAutoFill('create', $fill);

        $propKey = $this->normalizeWhiteAndBlack(
            array_flip($this->leevelChangedProp), 'create_prop'
        );

        $saveData = [];

        foreach ($this->leevelChangedProp as $prop) {
            if (!array_key_exists($prop, $propKey)) {
                continue;
            }

            $saveData[$prop] = $this->__get($prop);
        }

        if (!$saveData) {
            if (null === (($primaryKey = $this->primaryKeys()))) {
                $e = sprintf('Entity %s has no primary key.', static::class);

                throw new InvalidArgumentException($e);
            }

            foreach ($primaryKey as $value) {
                $saveData[$value] = null;
            }
        }

        $this->leevelFlush = function ($saveData) {
            $this->handleEvent(static::BEFORE_CREATE_EVENT, $saveData);

            $lastInsertId = $this->metaConnect()->insert($saveData);

            if ($auto = $this->autoIncrement()) {
                $this->withPropValue($auto, $lastInsertId, false, true);
            }

            $this->leevelNewed = false;

            $this->clearChanged();

            $this->handleEvent(static::AFTER_CREATE_EVENT, $saveData);

            return $lastInsertId;
        };

        $this->leevelFlushData = [$saveData];

        return $this;
    }
protected function createReal(?array $fill = null): IEntity
    {
        $this->leevelFlushed = false;

        $this->parseAutoFill('create', $fill);

        $propKey = $this->normalizeWhiteAndBlack(
            array_flip($this->leevelChangedProp), 'create_prop'
        );

        $saveData = [];

        foreach ($this->leevelChangedProp as $prop) {
            if (!array_key_exists($prop, $propKey)) {
                continue;
            }

            $saveData[$prop] = $this->__get($prop);
        }

        if (!$saveData) {
            if (null === (($primaryKey = $this->primaryKeys()))) {
                $e = sprintf('Entity %s has no primary key.', static::class);

                throw new InvalidArgumentException($e);
            }

            foreach ($primaryKey as $value) {
                $saveData[$value] = null;
            }
        }

        $this->leevelFlush = function ($saveData) {
            $this->handleEvent(static::BEFORE_CREATE_EVENT, $saveData);

            $lastInsertId = $this->metaConnect()->insert($saveData);

            if ($auto = $this->autoIncrement()) {
                $this->withPropValue($auto, $lastInsertId, false, true);
            }

            $this->leevelNewed = false;

            $this->clearChanged();

            $this->handleEvent(static::AFTER_CREATE_EVENT, $saveData);

            return $lastInsertId;
        };

        $this->leevelFlushData = [$saveData];

        return $this;
    }
添加数据.

@param null|array $fill

@return $this