Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

74 Zeilen
1.8KB

  1. <?php
  2. /**
  3. * This view is used by console/controllers/MigrateController.php
  4. * The following variables are available in this view:
  5. * @since 2.0.7
  6. * @deprecated since 2.0.8
  7. */
  8. /* @var $className string the new migration class name */
  9. /* @var $table string the name table */
  10. /* @var $field_first string the name field first */
  11. /* @var $field_second string the name field second */
  12. echo "<?php\n";
  13. ?>
  14. use yii\db\Migration;
  15. /**
  16. * Handles the creation of table `<?= $table ?>` which is a junction between
  17. * table `<?= $field_first ?>` and table `<?= $field_second ?>`.
  18. */
  19. class <?= $className ?> extends Migration
  20. {
  21. /**
  22. * @inheritdoc
  23. */
  24. public function up()
  25. {
  26. $this->createTable('<?= $table ?>', [
  27. '<?= $field_first ?>_id' => $this->integer(),
  28. '<?= $field_second ?>_id' => $this->integer(),
  29. 'PRIMARY KEY(<?= $field_first ?>_id, <?= $field_second ?>_id)',
  30. ]);
  31. $this->createIndex(
  32. 'idx-<?= $table . '-' . $field_first ?>_id',
  33. '<?= $table ?>',
  34. '<?= $field_first ?>_id'
  35. );
  36. $this->createIndex(
  37. 'idx-<?= $table . '-' . $field_second ?>_id',
  38. '<?= $table ?>',
  39. '<?= $field_second ?>_id'
  40. );
  41. $this->addForeignKey(
  42. 'fk-<?= $table . '-' . $field_first ?>_id',
  43. '<?= $table ?>',
  44. '<?= $field_first ?>_id',
  45. '<?= $field_first ?>',
  46. 'id',
  47. 'CASCADE'
  48. );
  49. $this->addForeignKey(
  50. 'fk-<?= $table . '-' . $field_second ?>_id',
  51. '<?= $table ?>',
  52. '<?= $field_second ?>_id',
  53. '<?= $field_second ?>',
  54. 'id',
  55. 'CASCADE'
  56. );
  57. }
  58. /**
  59. * @inheritdoc
  60. */
  61. public function down()
  62. {
  63. $this->dropTable('<?= $table ?>');
  64. }
  65. }