@@ -34,14 +34,13 @@ abstract class ActiveRecord extends \yii\db\ActiveRecord
...
@@ -34,14 +34,13 @@ abstract class ActiveRecord extends \yii\db\ActiveRecord
/**
/**
* Returns the database connection used by this AR class.
* Returns the database connection used by this AR class.
* By default, the "db" application component is used as the database connection.
* By default, the "redis" application component is used as the database connection.
* You may override this method if you want to use a different database connection.
* You may override this method if you want to use a different database connection.
* @return Connection the database connection used by this AR class.
* @return Connection the database connection used by this AR class.
*/
*/
publicstaticfunctiongetDb()
publicstaticfunctiongetDb()
{
{
// TODO
return\Yii::$app->redis;
return\Yii::$application->getDb();
}
}
/**
/**
...
@@ -124,6 +123,189 @@ abstract class ActiveRecord extends \yii\db\ActiveRecord
...
@@ -124,6 +123,189 @@ abstract class ActiveRecord extends \yii\db\ActiveRecord
thrownewNotSupportedException('getTableSchema() is not supported by redis ActiveRecord as there is no schema in redis DB. Schema is defined by AR class itself');
thrownewNotSupportedException('getTableSchema() is not supported by redis ActiveRecord as there is no schema in redis DB. Schema is defined by AR class itself');
}
}
/**
* Inserts a row into the associated database table using the attribute values of this record.
*
* This method performs the following steps in order:
*
* 1. call [[beforeValidate()]] when `$runValidation` is true. If validation
* fails, it will skip the rest of the steps;
* 2. call [[afterValidate()]] when `$runValidation` is true.
* 3. call [[beforeSave()]]. If the method returns false, it will skip the
* rest of the steps;
* 4. insert the record into database. If this fails, it will skip the rest of the steps;
* 5. call [[afterSave()]];
*
* In the above step 1, 2, 3 and 5, events [[EVENT_BEFORE_VALIDATE]],
* [[EVENT_BEFORE_INSERT]], [[EVENT_AFTER_INSERT]] and [[EVENT_AFTER_VALIDATE]]
* will be raised by the corresponding methods.
*
* Only the [[changedAttributes|changed attribute values]] will be inserted into database.
*
* If the table's primary key is auto-incremental and is null during insertion,
* it will be populated with the actual value after insertion.
*
* For example, to insert a customer record:
*
* ~~~
* $customer = new Customer;
* $customer->name = $name;
* $customer->email = $email;
* $customer->insert();
* ~~~
*
* @param boolean $runValidation whether to perform validation before saving the record.
* If the validation fails, the record will not be inserted into the database.
* @param array $attributes list of attributes that need to be saved. Defaults to null,
* meaning all attributes that are loaded from DB will be saved.
* @return boolean whether the attributes are valid and the record is inserted successfully.