Skip to content

Commit

Permalink
Merge pull request #268 from rhertogh/support_for_modelGenerateJuncti…
Browse files Browse the repository at this point in the history
…onRelationMode

Support for modelGenerateJunctionRelationMode
  • Loading branch information
schmunk42 authored Apr 20, 2020
2 parents b03af9a + f7effda commit 1439214
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 1 deletion.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
Changelog
=========

### 0.12.0

- Added support for `modelGenerateJunctionRelationMode`
- Upgraded `yiisoft/yii2-gii` to version 2.2.0

### 0.11.0

- *no changes*
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"dmstr/yii2-db": "*",
"friendsofphp/php-cs-fixer": "1.* || 2.*",
"yiisoft/yii2": "~2.0.13",
"yiisoft/yii2-gii": "~2.0.6 || ~2.1.0"
"yiisoft/yii2-gii": "~2.2.0"
},
"require-dev": {
"codeception/codeception": "^2.2",
Expand Down
5 changes: 5 additions & 0 deletions docs/25-cli-commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,11 @@ OPTIONS
database contains too many tables, you may want to uncheck this option to
accelerate the code generation process.
--modelGenerateJunctionRelationMode: string (defaults to 'table')
This indicates whether junction relations are generated with `viaTable()`
or `via()` relations, use 'table' or 'model' respectively.
Make sure you also generate the junction models when using the 'model' option.
--help, -h: boolean, 0 or 1
whether to display help information about current command.
Expand Down
7 changes: 7 additions & 0 deletions src/commands/BatchController.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,11 @@ class BatchController extends Controller
*/
public $modelGenerateRelations = ModelGenerator::RELATIONS_ALL;

/**
* @var
*/
public $modelGenerateJunctionRelationMode = ModelGenerator::JUNCTION_RELATION_VIA_TABLE;

/**
* @var bool whether the strings will be generated using `Yii::t()` or normal strings
*/
Expand Down Expand Up @@ -317,6 +322,7 @@ public function options($id)
'modelBaseClassSuffix',
'modelRemoveDuplicateRelations',
'modelGenerateRelations',
'modelGenerateJunctionRelationMode',
'modelGenerateQuery',
'modelQueryNamespace',
'modelQueryBaseClass',
Expand Down Expand Up @@ -431,6 +437,7 @@ public function actionModels()
'baseTraits' => $this->modelBaseTraits,
'removeDuplicateRelations' => $this->modelRemoveDuplicateRelations,
'generateRelations' => $this->modelGenerateRelations,
'generateJunctionRelationMode' => $this->modelGenerateJunctionRelationMode,
'tableNameMap' => $this->tableNameMap,
'generateQuery' => $this->modelGenerateQuery,
'queryNs' => $this->modelQueryNamespace,
Expand Down
1 change: 1 addition & 0 deletions src/generators/model/Generator.php
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ public function formAttributes()
'baseClass',
'db',
'generateRelations',
'generateJunctionRelationMode',
//'generateRelationsFromCurrentSchema',
'generateLabelsFromComments',
'generateHintsFromComments',
Expand Down
4 changes: 4 additions & 0 deletions src/generators/model/form.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@
Generator::RELATIONS_ALL => Yii::t('giiant', 'All relations'),
Generator::RELATIONS_ALL_INVERSE => Yii::t('giiant', 'All relations with inverse'),
]);
echo $form->field($generator, 'generateJunctionRelationMode')->dropDownList([
Generator::JUNCTION_RELATION_VIA_TABLE => Yii::t('giiant', 'Via Table'),
Generator::JUNCTION_RELATION_VIA_MODEL => Yii::t('giiant', 'Via Model'),
]);
//echo $form->field($generator, 'generateRelationsFromCurrentSchema')->checkbox();
echo $form->field($generator, 'generateLabelsFromComments')->checkbox();
echo $form->field($generator, 'generateHintsFromComments')->checkbox();
Expand Down

0 comments on commit 1439214

Please sign in to comment.