Cakephp 3 和 Postgres add.cpt 不工作 id_parent

Cakephp 3 and Postgres add.cpt doesnt work id_parent

我正在尝试使用 postgreSQL 在 cakephp 3 上创建一个简单的页面。 我不明白问题出在哪里: 我创建了一个 table "menus"。当我添加新实例 (add.cpt) 时,父字段为空,因此我无法添加父项。 全部由命令 "cake bake all menus".

生成

查看

<div class="actions columns large-2 medium-3">
    <h3><?= __('Actions') ?></h3>
    <ul class="side-nav">
        <li><?= $this->Html->link(__('List Menus'), ['action' => 'index']) ?></li>
    </ul>
</div>
<div class="menus form large-10 medium-9 columns">
    <?= $this->Form->create($menu); ?>
    <fieldset>
        <legend><?= __('Add Menu') ?></legend>
        <?php
            echo $this->Form->input('name');
            echo $this->Form->input('parent_id');
        ?>
    </fieldset>
    <?= $this->Form->button(__('Submit')) ?>
    <?= $this->Form->end() ?>
</div>

型号

public function initialize(array $config)
{
    $this->table('menus');
    $this->displayField('name');
    $this->primaryKey('id');
    $this->addBehavior('Timestamp');
    $this->belongsTo('ParentMenus', [
        'className' => 'Menus',
        'foreignKey' => 'parent_id'
    ]);
    $this->hasMany('ChildMenus', [
        'className' => 'Menus',
        'foreignKey' => 'parent_id'
    ]);
}

控制器

public function add()
{
    $menu = $this->Menus->newEntity();
    if ($this->request->is('post')) {
        $menu = $this->Menus->patchEntity($menu, $this->request->data);
        if ($this->Menus->save($menu)) {
            $this->Flash->success('The menu has been saved.');
            return $this->redirect(['action' => 'index']);
        } else {
            $this->Flash->error('The menu could not be saved. Please, try again.');
        }
    }
    $parentMenus = $this->Menus->ParentMenus->find('list', ['limit' => 200]);
    $this->set(compact('menu', 'parentMenus'));
    $this->set('_serialize', ['menu']);

}

Table 菜单

CREATE TABLE menus
(
  id serial NOT NULL,
  name character varying(255),
  created timestamp with time zone,
  modified time with time zone,
  parent_id integer,
  CONSTRAINT menus_pkey PRIMARY KEY (id),
  CONSTRAINT menus_parent_id_fkey FOREIGN KEY (parent_id)
      REFERENCES menus (id) MATCH SIMPLE
      ON UPDATE NO ACTION ON DELETE NO ACTION
)

将视图变量 $parentMenus 重命名为 $parents 或在视图中更改

echo $this->Form->input('parent_id');

echo $this->Form->input('parent_id', ['options' => $parentMenus]);