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

2.10.10 TranslateBehavior fails to restore old fields when bindTranslation is used #12376

Closed
1 of 3 tasks
mandricmihai opened this issue Jul 19, 2018 · 3 comments
Closed
1 of 3 tasks
Labels
Milestone

Comments

@mandricmihai
Copy link

mandricmihai commented Jul 19, 2018

This is a (multiple allowed):

  • bug

  • enhancement

  • feature-discussion (RFC)

  • CakePHP Version: 2.10.10

  • Platform and Target: Apache 2.4.23, PHP 7.1.14, MySQL 5.7.14, Windows 10 x64

What you did

I used Translate behavior to an model like so

public $actsAs = array(
		'Translate' => array(
			'description',
			'joinType' => 'LEFT'
                 ),
               'Containable',
	);

And everything works as expected.
But given the use case:

             $this->Model->bindTranslation(array('description' => 'description_translations'), true);
             $this->Model->find('first',array(
			 'conditions' => [
				'Model.id' => $id,
			],
			'contain' => array(
				'description_translations'
			)
	      ));
              $this->Model->find('first',array(
			'fields' => array(
				'Model.description',
			),
			'conditions' => [
				'Model.id' => $id,
			],
		));
		$this->Model->find('first',array(
			'fields' => array(
				'Model.description',
			),
			'conditions' => [
				'Model.id' => $id,
			],
		));

What happened

The last call to find() will fail with:

Column not found: 1054 Unknown column 'Model.description' in 'field list'

So why does this happen?

What you expected to happen

I would expect that $reset = true to bindTranslation() will just reset the fields to original after it run not to empty.
As a side note the doc is wrong https://api.cakephp.org/2.10/source-class-TranslateBehavior.html#643
According to the doc the second find() should fail but it was the third that failed.

As a fix we could replace this line https://github.com/cakephp/cakephp/blob/2.x/lib/Cake/Model/Behavior/TranslateBehavior.php#L347
with $this->runtime[$Model->alias]['virtualFields'] = array();
So that if we use bindTranslation() the old fields will be used not empty. (not 100% about this fix, clearly there are multiple ways to fix this)

Or all of this could be intended and I just lost 1 day for nothing 😢

@markstory markstory added this to the 2.10.12 milestone Jul 19, 2018
@markstory
Copy link
Member

Could you send a pull request with the change that would solve the issue you're having? If the current tests pass what you're expecting sounds reasonable to me.

mandricmihai pushed a commit to mandricmihai/cakephp that referenced this issue Jul 19, 2018
@mandricmihai
Copy link
Author

@markstory pull request #12378

@markstory
Copy link
Member

Thank you 👍

markstory added a commit that referenced this issue Jul 30, 2018
Fixes #12376 bindTranslation restore fields
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants