0
votes

Cakephp seems to be adding the property "_locale" on "contain" associations, its ok if this property sits inside the Entity object, but not in the array that holds the associations as it will break a lot of stuff, this only happens when the language is not the default and the Model has the translate behavior, any ideas on how to fix / remove it?

[product_variations] => Array(
[0] => App\Model\Entity\ProductsVariation Object(
    [id] => 15
    [product_id] => 12
    [name] => Adults
    [description] => <p>Adult Ticket</p>
    [price_mode] => final
    [price] => 15
    [stock] => -1
    [weight] => 0
    [sku] => OITGXNRMARTPPDV
    [data] => 
    [active] => 1
    [enquire] => 
    [position] => 1
    [products_prices] => Array
        (
        )

    [_locale] => pt
    [[new]] => 
    [[accessible]] => Array
        (
            [*] => 1
        )

    [[dirty]] => Array
        (
        )

    [[original]] => Array
        (
        )

    [[virtual]] => Array
        (
        )

    [[errors]] => Array
        (
        )

    [[invalid]] => Array
        (
        )

    [[repository]] => ProductVariations
),
[_locale] => pt

)

Update: Seems to be due to the use of the "matching" method "Model->find(...)->matching('ProductVariations')...

1
I've never seen that before... please provide a way to reproduce this.ndm
Removing the matching method from the query resolves the issue, however is not desired...JVieira
Looks like a bug... I'd suggest to report it over at GitHub, ideally with a test case attached.ndm

1 Answers

0
votes

The manual explains it:

So, after you save your first article, you can now save a translation for it, there are a couple ways to do it. The first one is setting the language directly into the entity:

$article->_locale = 'es';
$article->title = 'Mi primer Artículo';
$this->Articles->save($article);

So be aware of this when you modify the data. I don't know what happens if you remove it and then save the record or try do some something else i18n related with it. :)

The code related to this property is here in the TranslateTrait.

You can try to add a result formatter by calling formatResults() on the query and unset this property from there.