This commit is contained in:
2021-08-02 16:38:50 +08:00
parent fd7415b7f1
commit a095c94e21
15 changed files with 1593 additions and 1513 deletions
+22 -6
View File
@@ -43,7 +43,7 @@ use validator\Validator;
* @property bool $isCreate
* @method rules()
* @method static tableName()
* @property Application $application
* @property Application $container
*/
abstract class BaseActiveRecord extends Component implements IOrm, ArrayAccess
{
@@ -106,7 +106,7 @@ abstract class BaseActiveRecord extends Component implements IOrm, ArrayAccess
/**
* @return Application
*/
#[Pure] private function getApplication(): Application
#[Pure] private function getContainer(): Application
{
return Snowflake::app();
}
@@ -322,14 +322,30 @@ abstract class BaseActiveRecord extends Component implements IOrm, ArrayAccess
/**
* @return ActiveQuery
* @throws ReflectionException
* @throws NotFindClassException
*/
public static function find(): ActiveQuery
{
return Snowflake::createObject(ActiveQuery::class, [static::class]);
return new ActiveQuery(get_called_class());
}
/**
* @return ActiveQuery
*/
public static function query(): ActiveQuery
{
return new ActiveQuery(get_called_class());
}
/**
* @throws ConfigException
*/
protected function getConnection()
{
return Config::get('connections.' . static::$ab_name, null, true);
}
/**
* @param null $condition
* @param array $attributes
@@ -710,7 +726,7 @@ abstract class BaseActiveRecord extends Component implements IOrm, ArrayAccess
* @return bool
* @throws Exception
*/
#[Event(ActiveRecord::AFTER_SAVE)]
#[Event(self::AFTER_SAVE)]
public function afterSave($attributes, $changeAttributes): bool
{
return true;