Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
huangzhhui authored Jun 14, 2018
1 parent 75e5701 commit 78dde00
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/Executor.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use Swoft\Db\Exception\MysqlException;
use Swoft\Db\Validator\ValidatorInterface;
use Swoft\Exception\ValidatorException;
use Swoft\Helper\StringHelper;

/**
* Executor
Expand All @@ -36,7 +37,13 @@ public static function save($entity): ResultInterface

$fields = $fields ?? [];
$query = Query::table($table)->selectInstance($instance);

// Set Primary Id to Entity
$query->addDecorator(function ($primaryId) use ($entity, $className) {
list(, , $idColumn) = self::getTable($className);
$setter = 'set' . StringHelper::camel($idColumn, false);
method_exists($entity, $setter) && $entity->$setter($primaryId);
return $primaryId;
});
return $query->insert($fields);
}

Expand Down

0 comments on commit 78dde00

Please sign in to comment.