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

Translate behavior issue when model only contains the translated field #9610

Closed
1 of 3 tasks
andrej-griniuk opened this issue Oct 13, 2016 · 9 comments
Closed
1 of 3 tasks

Comments

@andrej-griniuk
Copy link
Contributor

This is a (multiple allowed):

  • bug
  • enhancement
  • feature-discussion (RFC)
  • CakePHP Version: 3.3.5
  • Platform and Target: MySQL 5.6

What you did

Create a table with only 2 fields. Let's say countries [id, name]. Bake everything. Add Translate behaviour $this->addBehavior('Translate', ['fields' => ['name']]); to the Table and use TranslateTrait; to the Entity. Go to countries/add and try to add a new Country with name "USA".

Expected Behavior

New country created in countries table with "USA" name in the i18n table.

Actual Behavior

"The country could not be saved. Please, try again.". If inspect $country in the controller - no errors there.

andrej-griniuk added a commit to CakeDC/cakephp that referenced this issue Oct 13, 2016
@markstory
Copy link
Member

Does the original table contain both the id and name fields or only id?

@andrej-griniuk
Copy link
Contributor Author

Both.
As I understand this is what's happening: Translate behaviour marks translated fields as not dirty (https://github.com/cakephp/cakephp/blob/master/src/ORM/Behavior/TranslateBehavior.php#L315) then in Table _insert method $data is empty (id is null, no fields are dirty) and it returns false(https://github.com/cakephp/cakephp/blob/master/src/ORM/Table.php#L1665)

@markstory
Copy link
Member

Based on the referenced lines you're saving a model in a non-default locale as well?

@markstory markstory modified the milestones: 3.3.6, 3.3.7 Oct 15, 2016
@andrej-griniuk
Copy link
Contributor Author

Nope, in the default locale.

@lorenzo
Copy link
Member

lorenzo commented Oct 15, 2016

If it's the default locale, how come there are no dirty fields? The default locale is meant to be saved in the main table

@andrej-griniuk
Copy link
Contributor Author

Double checked, you're right, it's not the default locale.
But this is still an issue I recon.

@lorenzo
Copy link
Member

lorenzo commented Oct 16, 2016

Do you mind writing a test case for the core? That would help greatly to investigate the issue

@andrej-griniuk
Copy link
Contributor Author

@markstory markstory self-assigned this Oct 16, 2016
markstory added a commit that referenced this issue Oct 22, 2016
When we have bundled translations but no changed fields, we need to mark
the original fields dirty so we can save the root entity and the
attached translations.

Refs #9610
@markstory
Copy link
Member

Thanks for the test @andrej-griniuk. I've got a pull request up now.

lorenzo added a commit that referenced this issue Oct 24, 2016
Fix saving translations when only translations are modified.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants