# |
May 2nd 2019, 20:26 |
noel |
But then it will look for the parents table. There is no parents table. |
# |
May 2nd 2019, 20:26 |
waspinator |
join tables should be named with their associated table names. so `tests_parents` instead of `tests_tests` |
# |
May 2nd 2019, 20:24 |
noel |
Same error message. |
# |
May 2nd 2019, 20:24 |
slackebot |
->create(); } public function down() { $this->table('tests')->drop()->save(); $this->table('tests_tests')->drop()->save(); } } ``` |
# |
May 2nd 2019, 20:24 |
slackebot |
=> false, ]) ->addPrimaryKey(['id']) ->addColumn('test_id', 'integer', [ 'default' => null, 'limit' => 11, 'null' => false, 'signed' => false, ]) ->addColumn('parent_id', 'integer', [ 'default' => null, 'limit' => 11, 'null' => false, 'signed' => false, ]) |
# |
May 2nd 2019, 20:24 |
slackebot |
->addPrimaryKey(['id']) ->addColumn('name', 'string', [ 'default' => null, 'limit' => 255, 'null' => true, ]) ->create(); $this->table('tests_tests') ->addColumn('id', 'integer', [ 'autoIncrement' => true, 'default' => null, 'limit' => 11, 'null' => false, 'signed' |
# |
May 2nd 2019, 20:24 |
noel |
Here’s the updated migration: ``` <?php use Migrations\AbstractMigration; class Initial extends AbstractMigration { public $autoId = false; public function up() { $this->table('tests') ->addColumn('id', 'integer', [ 'autoIncrement' => true, 'default' => null, 'limit' => 11, 'null' => false, 'signed' => false, ]) |
# |
May 2nd 2019, 20:24 |
noel |
@waspinator ok I can make it so.. but it still doesn’t fix the error :slightly_smiling_face: |
# |
May 2nd 2019, 20:23 |
waspinator |
there should only be a single primarykey, the `id` field. set use `$table->addIndex(['test_id', 'parent_id']);` instead |
# |
May 2nd 2019, 20:22 |
noel |
@waspinator tx for the feedback. it’s a link table for self-referenced many to many records from tests. You say it needs an id as well… why? It’s just a link table. Other many-to-many relationships work fine with Bake without their own id fields. Also adding the id field doesn’t fix the error. |
# |
May 2nd 2019, 20:16 |
waspinator |
your `tests_tests` table `belongsTo` the `tests` and `parent` tables, but it needs it's own `id` as well |
# |
May 2nd 2019, 20:15 |
waspinator |
normally every table should have an `id` column |
# |
May 2nd 2019, 20:14 |
waspinator |
what is `'tests_tests'` table supposed to be for? |
# |
May 2nd 2019, 20:11 |
slackebot |
->addColumn('parent_id', 'integer', [ 'default' => null, 'limit' => 11, 'null' => false, 'signed' => false, ]) ->addPrimaryKey(['test_id', 'parent_id']) ->create(); } public function down() { $this->table('tests')->drop()->save(); $this->table('tests_tests')->drop()->save(); } } ``` |
# |
May 2nd 2019, 20:11 |
slackebot |
->addPrimaryKey(['id']) ->addColumn('name', 'string', [ 'default' => null, 'limit' => 255, 'null' => true, ]) ->create(); $this->table('tests_tests') ->addColumn('test_id', 'integer', [ 'default' => null, 'limit' => 11, 'null' => false, 'signed' => false, ]) |
# |
May 2nd 2019, 20:11 |
noel |
@waspinator ``` <?php use Migrations\AbstractMigration; class Initial extends AbstractMigration { public $autoId = false; public function up() { $this->table('tests') ->addColumn('id', 'integer', [ 'autoIncrement' => true, 'default' => null, 'limit' => 11, 'null' => false, 'signed' => false, ]) |
# |
May 2nd 2019, 19:29 |
waspinator |
https://book.cakephp.org/3.0/en/migrations.html#generating-migrations-from-an-existing-database |
# |
May 2nd 2019, 19:28 |
waspinator |
@noel |
# |
May 2nd 2019, 19:28 |
waspinator |
user `bin/cake bake migration_snapshot Initial` to generate your table migrations from your database, and share them to help troubleshoot |
# |
May 2nd 2019, 16:42 |
noel |
I’ve tried removing the Primary keys – it doesn’t change the error.. so for some reason it’s still saying “some of the primary key values are missing” |
# |
May 2nd 2019, 16:40 |
noel |
@josbeir but I’ve selected tests from the select – which should define parent_id. Also having null values in a link table will cause any many to many relationship to break. |
# |
May 2nd 2019, 16:38 |
noel |
If not concatenated keys, then which should be primary? It’s a link table – my understanding is that for link tables both are primary. What do you suggest instead? |
# |
May 2nd 2019, 16:37 |
noel |
What do you mean by this? “That, and giving Cake the expected table names for the relationships” |
# |
May 2nd 2019, 16:36 |
noel |
@daniel.upshaw Yes I’m using the same table names as in the SO post. |
# |
May 2nd 2019, 16:24 |
daniel.upshaw |
And add `lft` and `rght` columns |
# |
May 2nd 2019, 16:23 |
daniel.upshaw |
You would add this behavior to your `tests` table: https://book.cakephp.org/3.0/en/orm/behaviors/tree.html |
# |
May 2nd 2019, 16:23 |
daniel.upshaw |
I like using concatenated keys... but in the case of Cake/bake, I try to keep it simpler.. There may be some way to make it use concatenated keys, but you might use an `id` column on your pivot table.. Why wouldn't your `parent_id` be in the test table itself? |
# |
May 2nd 2019, 16:22 |
daniel.upshaw |
Oh... also it looks like you are using a concatenated key, that could be the issue |
# |
May 2nd 2019, 16:20 |
daniel.upshaw |
I'm not 100% sure if Cake reads the foreign keys, but it wouldn't hurt to have them defined just in case.. That, and giving Cake the expected table names for the relationships should make it bake properly |
# |
May 2nd 2019, 16:19 |
daniel.upshaw |
And I see that you do not have foreign keys defined? |
# |
May 2nd 2019, 16:18 |
daniel.upshaw |
@noel How are your tables named? Are you using the same table names as in the SO post? |
# |
May 2nd 2019, 16:02 |
josbeir |
an because its many to many i dont think test_id or parent_id can be a PK |
# |
May 2nd 2019, 16:01 |
josbeir |
make it so that parent_id can bel null |
# |
May 2nd 2019, 16:01 |
josbeir |
@noel isnt that just because it tries to create a record in tests_tests and tries to fill in parent_id which is not defined |
# |
May 2nd 2019, 15:35 |
noel |
Any ideas? |
# |
May 2nd 2019, 15:29 |
noel |
Here’s the problem I’m having with bake. It doesn’t seem to work for self-referencing many-to-many relationships. It detects them but is unable to write such records without error: https://stackoverflow.com/questions/55955731/how-to-get-self-referencing-many-to-many-relationship-to-work-for-cake-bake-scaf |
# |
May 2nd 2019, 15:05 |
lorro |
Got a next problem in the process of updating to cakePHP 3.7. Since removing Plugin::routes() from bootstrap.php my Plugin routes don't get loaded correctly anymore. In Application.php I have loaded the RoutingMiddleware as in the app skeleton on github. `->add(new RoutingMiddleware($this, '_cake_routes_'));` The plugin is loaded like this: `$this->addPlugin('TBApi', ['routes' => true]);` Do I miss anything here? Thanks |
# |
May 2nd 2019, 15:00 |
noel |
Cake bake doesn’t seem to do anything with any `belongsToMany` associations that it finds. Why is that? |
# |
May 2nd 2019, 14:46 |
neon1024 |
:thumbsup: |
# |
May 2nd 2019, 14:43 |
daniel.upshaw |
Thank you |
# |
May 2nd 2019, 14:43 |
daniel.upshaw |
@neon1024 That worked!! |