This commit is contained in:
2021-04-12 16:19:21 +08:00
parent 7b5c38dc4b
commit 779ec7e8d0
2 changed files with 20 additions and 24 deletions
-1
View File
@@ -114,7 +114,6 @@ class ActiveRecord extends BaseActiveRecord
* @param array $condition * @param array $condition
* @param array $attributes * @param array $attributes
* @return bool|ActiveRecord * @return bool|ActiveRecord
* @throws ComponentException
* @throws ReflectionException * @throws ReflectionException
* @throws NotFindClassException * @throws NotFindClassException
* @throws Exception * @throws Exception
+20 -23
View File
@@ -10,32 +10,29 @@ declare(strict_types=1);
namespace Database\Base; namespace Database\Base;
use Annotation\Aspect;
use Annotation\Event; use Annotation\Event;
use Annotation\Inject; use Annotation\Inject;
use ArrayAccess; use ArrayAccess;
use Database\InjectProperty;
use Database\SqlBuilder;
use Database\Traits\HasBase;
use HttpServer\Http\Context;
use ReflectionException;
use Snowflake\Abstracts\Component;
use Database\ActiveQuery; use Database\ActiveQuery;
use Database\ActiveRecord; use Database\ActiveRecord;
use Database\Connection; use Database\Connection;
use Database\HasMany; use Database\HasMany;
use Database\HasOne; use Database\HasOne;
use Database\IOrm;
use Database\Mysql\Columns; use Database\Mysql\Columns;
use Database\Relation; use Database\Relation;
use Database\SqlBuilder;
use Database\Traits\HasBase;
use Exception; use Exception;
use HttpServer\Http\Context;
use ReflectionException;
use Snowflake\Abstracts\Component;
use Snowflake\Abstracts\TraitApplication; use Snowflake\Abstracts\TraitApplication;
use Snowflake\Channel; use Snowflake\Channel;
use Snowflake\Exception\ComponentException;
use Snowflake\Exception\NotFindClassException;
use validator\Validator;
use Database\IOrm;
use Snowflake\Snowflake;
use Snowflake\Event as SEvent; use Snowflake\Event as SEvent;
use Snowflake\Exception\NotFindClassException;
use Snowflake\Snowflake;
use validator\Validator;
/** /**
* Class BOrm * Class BOrm
@@ -391,13 +388,13 @@ abstract class BaseActiveRecord extends Component implements IOrm, ArrayAccess
*/ */
public function getAttributes(): array public function getAttributes(): array
{ {
$data = $this->_attributes; $data = $this->_attributes;
foreach ($this->getAnnotation() as $key => $item) { foreach ($this->getAnnotation() as $key => $item) {
if (!isset($data[$key])) continue; if (!isset($data[$key])) continue;
$data[$key] = $this->runAnnotation($key, $data[$key] ?? null); $data[$key] = $this->runAnnotation($key, $data[$key] ?? null);
} }
return $data; return $data;
} }
/** /**
@@ -768,14 +765,14 @@ abstract class BaseActiveRecord extends Component implements IOrm, ArrayAccess
$tablePrefix = static::getDb()->tablePrefix; $tablePrefix = static::getDb()->tablePrefix;
$table = static::tableName(); $table = static::tableName();
if (empty($table)) {
throw new Exception('You need add static method `tableName` and return table name.');
}
if (str_starts_with($table, $tablePrefix)) { if (str_starts_with($table, $tablePrefix)) {
return $table; return $table;
} } else if (!str_starts_with($table, '{{%')) {
return $table;
if (empty($table)) {
$class = preg_replace('/model\\\\/', '', get_called_class());
$table = lcfirst($class);
} }
$table = trim($table, '{{%}}'); $table = trim($table, '{{%}}');