Created
July 29, 2016 07:18
-
-
Save mdmunir/f8afa9c70317089a86a08d4e2bf68b43 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace app\classes; | |
use Yii; | |
use yii\db\BaseActiveRecord; | |
use yii\db\Query; | |
use yii\db\ActiveQuery; | |
use yii\helpers\Inflector; | |
use yii\helpers\StringHelper; | |
use yii\base\NotSupportedException; | |
/** | |
* Description of QueryRecord | |
* | |
* @author Misbahul D Munir <[email protected]> | |
* @since 1.0 | |
*/ | |
abstract class QueryRecord extends BaseActiveRecord | |
{ | |
/** | |
* @return Query | |
*/ | |
abstract public static function query(); | |
public function insert($runValidation = true, $attributes = null) | |
{ | |
throw new NotSupportedException(__METHOD__ . ' is not supported.'); | |
} | |
/** | |
* @return ActiveQuery | |
*/ | |
public static function find() | |
{ | |
return Yii::createObject(ActiveQuery::className(), [get_called_class()]) | |
->from([Inflector::camel2id(StringHelper::basename(get_called_class()), '_') => static::query()]); | |
} | |
public static function getDb() | |
{ | |
return Yii::$app->getDb(); | |
} | |
public static function primaryKey() | |
{ | |
return []; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment