0
votes

I tried to bake my MVC in cakephp 3. I used Migrations to create my table including the foreign keys. Here's the code I use for migrations

{
$utTable = $this->table('unit_types');
    $utTable
        ->addColumn('unit_type_desc','string')
        ->addColumn('created','datetime')
        ->addColumn('modified','datetime')
        ->create();
    $mlTable = $this->table('master_lists');
    $mlTable
        ->addColumn('unit_type_id','integer')
        ->addForeignKey('unit_type_id', 'unit_types', 'id')
        ->addColumn('created','datetime')
        ->addColumn('modified','datetime')
        ->create();
}

It prompts no error and seems to work well. but when I bake the master lists I got some errors, I saw '0 columns' phrase or something like that and a few more.

Now my question is, is this the proper way to put data association in cakephp? or should I be using my model files? I have no idea. I'm new to this framework. Thanks for any answers.

1

1 Answers

1
votes

I don't know if you solve your problem, but I would suggest you to use save() instead of create().

For anyone searching the same topic, Cakephp 3 use the library Phinx to handle migrations, here is info about your problem: http://docs.phinx.org/en/latest/migrations.html#working-with-foreign-keys