Skip to content

Commit

Permalink
Gii model generator improve
Browse files Browse the repository at this point in the history
  • Loading branch information
demisang committed Nov 21, 2017
1 parent c1af0dc commit 8df6e35
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
16 changes: 10 additions & 6 deletions gii/model.php
Expand Up @@ -35,8 +35,9 @@
<?php endforeach; ?>
<?php if (!empty($relations)): ?>
*
* relations
<?php foreach ($relations as $name => $relation): ?>
* @property <?= $relation[1] . ($relation[2] ? '[]' : '') . ' $' . lcfirst($name) . "\n" ?>
* @property-read <?= $relation[1] . ($relation[2] ? '[]' : '') . ' $' . lcfirst($name) . "\n" ?>
<?php endforeach; ?>
<?php endif; ?>
*/
Expand Down Expand Up @@ -80,7 +81,7 @@ public static function getDb()
public function scenarios()
{
$scenarios = parent::scenarios();
$scenarios['default'] = [<?= implode(', ', $columns); ?>];
$scenarios[self::SCENARIO_DEFAULT] = [<?= implode(', ', $columns); ?>];

return $scenarios;
}
Expand All @@ -107,6 +108,8 @@ public function attributeLabels()
<?php foreach ($relations as $name => $relation): ?>

/**
* <?= $name ?> relation
*
* @return \yii\db\ActiveQuery
*/
public function get<?= $name ?>()
Expand All @@ -123,8 +126,8 @@ public function behaviors()
return [
[
'class' => 'demi\helpers\behaviors\TimestampBehavior',
'createdAtAttribute' => 'created_at',
'updatedAtAttribute' => 'updated_at',
'createdAtAttribute' => 'createdAt',
'updatedAtAttribute' => 'updatedAt',
],
];
}
Expand Down Expand Up @@ -156,8 +159,9 @@ public function afterSave($insert, $changedAttributes)
/**
* @inheritdoc
*/
public function afterDelete() {
// Do not forget delete the related data!
public function afterDelete()
{
// Do not forget remove related data!

parent::afterDelete();
}
Expand Down
11 changes: 10 additions & 1 deletion gii/query.php
Expand Up @@ -84,4 +84,13 @@ public function one($db = null)
{
return parent::one($db);
}
}

/**
* @inheritdoc
* @return \yii\db\BatchQueryResult|<?= $modelFullClassName ?>[]|array
*/
public function each($batchSize = 100, $db = null)
{
return parent::each($batchSize, $db);
}
}

0 comments on commit 8df6e35

Please sign in to comment.