diff --git a/Database/ActiveRecord.php b/Database/ActiveRecord.php index 7db41407..77ec8c57 100644 --- a/Database/ActiveRecord.php +++ b/Database/ActiveRecord.php @@ -114,7 +114,6 @@ class ActiveRecord extends BaseActiveRecord * @param array $condition * @param array $attributes * @return bool|ActiveRecord - * @throws ComponentException * @throws ReflectionException * @throws NotFindClassException * @throws Exception diff --git a/Database/Base/BaseActiveRecord.php b/Database/Base/BaseActiveRecord.php index a02bf3ec..83d90f62 100644 --- a/Database/Base/BaseActiveRecord.php +++ b/Database/Base/BaseActiveRecord.php @@ -10,32 +10,29 @@ declare(strict_types=1); namespace Database\Base; -use Annotation\Aspect; use Annotation\Event; use Annotation\Inject; 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\ActiveRecord; use Database\Connection; use Database\HasMany; use Database\HasOne; +use Database\IOrm; use Database\Mysql\Columns; use Database\Relation; +use Database\SqlBuilder; +use Database\Traits\HasBase; use Exception; +use HttpServer\Http\Context; +use ReflectionException; +use Snowflake\Abstracts\Component; use Snowflake\Abstracts\TraitApplication; 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\Exception\NotFindClassException; +use Snowflake\Snowflake; +use validator\Validator; /** * Class BOrm @@ -391,13 +388,13 @@ abstract class BaseActiveRecord extends Component implements IOrm, ArrayAccess */ public function getAttributes(): array { - $data = $this->_attributes; - foreach ($this->getAnnotation() as $key => $item) { - if (!isset($data[$key])) continue; + $data = $this->_attributes; + foreach ($this->getAnnotation() as $key => $item) { + if (!isset($data[$key])) continue; - $data[$key] = $this->runAnnotation($key, $data[$key] ?? null); - } - return $data; + $data[$key] = $this->runAnnotation($key, $data[$key] ?? null); + } + return $data; } /** @@ -768,14 +765,14 @@ abstract class BaseActiveRecord extends Component implements IOrm, ArrayAccess $tablePrefix = static::getDb()->tablePrefix; $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)) { return $table; - } - - if (empty($table)) { - $class = preg_replace('/model\\\\/', '', get_called_class()); - $table = lcfirst($class); + } else if (!str_starts_with($table, '{{%')) { + return $table; } $table = trim($table, '{{%}}');