How Can search in translation fields

I have table “Items”
id + name+ content

and the translation table is:
id + locale + name + content

so I need to search in name column by current locale

I think it would be better if you have a foreign-key to link both tables together (Items and ItemsTranslation table). See Associations on how to do it.

Do you think the best association is HasMany Associations
and I do this association how can search in it ?

The translated field in the current locale is being joined in automatically by the translate behavior, that’s what you can filter on. The behavior’s translationField() method will give you the proper name of the field to use in your conditions:

$query = $this->Items
        $this->Items->translationField('name') => 'John Doe',

1 Like

That’s work find, but what I want to find in multi columns with “OR” conditions

You’d do it just like with any other field, there’s nothing special about translation fields, other than that you retrieve them dynamically instead of hardcoding them. Either use the special OR key, or the IN operator:

    'OR' => [
        [$this->Items->translationField('name') => 'John Doe'],
        [$this->Items->translationField('name') => 'Jane Doe'],

    $this->Items->translationField('name') . ' IN' => [
        'John Doe',
        'Jane Doe',

1 Like

what about one of them translationField and the other non translationField
how can search by AND or OR.

Just try using different field names and see what happens. Have you to read the linked documentation?