Pass ['accessibleFields' => ['*' => true]]; to your newEntity method. You are hitting mass assignment prevention
On Friday, April 17, 2015 at 8:58:22 AM UTC+2, uru...@gmail.com wrote:
-- On Friday, April 17, 2015 at 8:58:22 AM UTC+2, uru...@gmail.com wrote:
When I try to load data into a migration I get the following error message:
[RuntimeException]
Cannot insert row, some of the primary key values are missing. Got (, ), ex
pecting (article_id, tag_id)
from this code:
<?php
use Cake\ORM\TableRegistry;
use Phinx\Migration\AbstractMigration ;
class SeedMigration extends AbstractMigration
{
public function change()
{
$this->table('articles_tags', ['id' => false, 'primary_key' => ['article_id', 'tag_id']])
->addColumn('article_id', 'integer')
->addForeignKey('article_id', 'articles', 'id')
->addColumn('tag_id', 'integer')
->addForeignKey('tag_id', 'tags', 'id')
->save();
$articlesTags = TableRegistry::get('ArticlesTags' );
$articleTag = [
'article_id' => 1,
'tag_id' => 1,
];
$articlesTags->save($articlesTags ->newEntity($articleTag ));
}
}
NOTE: Articles and Tags are created before and there are data with id 1
regards --cesar
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP
---
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cake-php+unsubscribe@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.
No comments:
Post a Comment