Wednesday, May 13, 2015

Re: Appliying translate behavior in 3.0 to already existing rows

The behavior is thought so that the main application language is store in the real table and all the translations in the i18n table

On Tuesday, May 12, 2015 at 10:40:25 AM UTC+2, Aday Talavera wrote:
While following the guide http://book.cakephp.org/3.0/en/orm/behaviors/translate.html  to apply translate behaviour to my models I detected some problems, but I don't know if I'm following bad the guide or if the guide needs to be improved.

Let me explain using an example.

I had this table in my system and wanted to apply translate behavior.

CREATE TABLE `boards` (
 
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
 
`name` varchar(100) NOT NULL,
 
`description` text,
  PRIMARY KEY
(`id`)
) ENGINE=InnoDB  DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;

So I added this to BoardsTable initialize method:

$this->addBehavior('Translate', [
           
'fields' => ['name', 'description'],
       
]);

And added TranslateTrait to BoardEntity

In that scenario I detected the next things:
  1. If I create a new board providing english and spanish texts, they are stored correctly in i18n table.
  2. If I edit an existing board before applying Translate behavior, current locale language (spanish) is stored in boards.name and boards.description while english locale is stored in i18n table.
  3. If I nullify name and description fields before editing the row in point 2, everything is stored in i18n table.

How can we avoid point 2 issue? Is a bug or I missed something?

Cheers.

--
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: