Sitelet https://web.archive.org/web/20210815130332/https://github.com/cakephp/cakephp/issues/15407
Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to save associated BTM data #15407

Open
1 of 3 tasks
patrickconroy opened this issue Mar 22, 2021 · 1 comment
Open
1 of 3 tasks

Unable to save associated BTM data #15407

patrickconroy opened this issue Mar 22, 2021 · 1 comment
Milestone

Comments

@patrickconroy
Copy link
Task lists! Give feedback
Contributor

@patrickconroy patrickconroy commented Mar 22, 2021

This is a (multiple allowed):

  • bug

  • enhancement

  • feature-discussion (RFC)

  • CakePHP Version: 4.2.4

  • Platform and Target: PHP 7.4.12, MacOS 10.15.7

What you did

Trying to patch/save a belongs to many association data when a primary key is non-standard (in the sense that I have a composite pk) doesn't work.

#PostsTable
'belongsToMany' => [
    'Tags' => [
        'through' => 'PostsTags',
    ],
],

#PostsTagsTable
public function initialize(array $config): void
{
    $this->setPrimaryKey(['post_id', 'tag_id', 'primary']);
}

#Save function in PostsTable
$tags = [
    [
        'id' => 123,
        '_joinData' => ['primary' => 1],
    ],
];
$post = $this->get(155);
$this->patchEntity($post, compact('tags'));
$this->save($post);

What happened

Cannot insert row, some of the primary key values are missing. Got (155, 123, ), expecting (post_id, tag_id, primary)

What you expected to happen

I should be able to patch the $post and have it save the Tags association. This is working for me in my old Cake 3.3 project. I've tried debugging on my own but I don't know where the marshaller is going wrong or if the shape of my data is wrong.

@markstory markstory added this to the 4.2.5 milestone Mar 22, 2021
@markstory
Copy link
Member

@markstory markstory commented Mar 22, 2021

Is the primary column part of your primary key data? Do you have a stacktrace for the error you're getting?

@markstory markstory removed this from the 4.2.5 milestone Apr 3, 2021
@markstory markstory added this to the 4.2.6 milestone Apr 3, 2021
@markstory markstory removed this from the 4.2.6 milestone May 5, 2021
@markstory markstory added this to the 4.2.7 milestone May 5, 2021
@markstory markstory removed this from the 4.2.7 milestone Jun 16, 2021
@markstory markstory added this to the 4.2.8 milestone Jun 16, 2021
@markstory markstory removed this from the 4.2.8 milestone Jul 17, 2021
@markstory markstory added this to the 4.2.9 milestone Jul 17, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants