0
votes

I would like to know how to retrieve translation inside a query with cakephp 3.3. I have already added inside Table:

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

This is my query:

$query = $objTable->find('all')
     ->where(['admin_template_id' => $id])
     ->contain(['AdminObjects']);

I have already tried this:

$query = $objTable->find('all')
         ->where(['admin_template_id' => $id])
         ->contain(['AdminObjects', 'translations']);

But returns me error 500.

My translation table is the same of the cakephp documentation:

CREATE TABLE i18n (
    id int NOT NULL auto_increment,
    locale varchar(6) NOT NULL,
    model varchar(255) NOT NULL,
    foreign_key int(10) NOT NULL,
    field varchar(255) NOT NULL,
    content text,
    PRIMARY KEY     (id),
    UNIQUE INDEX I18N_LOCALE_FIELD(locale, model, foreign_key, field),
    INDEX I18N_FIELD(model, foreign_key, field)
);

How can I fin translation inside a find all query?

Thanks

1

1 Answers

1
votes

You may use find method 'translations' instate of 'all'.

try

$query = $objTable->find('translations')
 ->where(['admin_template_id' => $id])
 ->contain(['AdminObjects']);

instate of

$query = $objTable->find('all')
 ->where(['admin_template_id' => $id])
 ->contain(['AdminObjects']);

officeial Doc Retrieve All Translations