I18n and concrete inheritance #508

pimpreneil opened this Issue Nov 19, 2012 · 1 comment


None yet

2 participants


When using concrete inheritance with i18n, the parent's i18n fields are not updated when set from a child.

For example, if we create a table "Campain" like this:

<table name="campain" phpName="Campain">
    <column name="id" type="integer" required="true" primaryKey="true" autoIncrement="true" />
    <column name="name" type="varchar" required="true" primaryString="true" />

    <behavior name="i18n">
        <parameter name="i18n_columns" value="name" />

And a table "CampainAlert" that extends it:

<table name="campain_alert" phpName="CampainAlert" allowPkInsert="true">
    <behavior name="concrete_inheritance">
        <parameter name="extends" value="campain" />

The if we create a new CampainAlert, setting the inherited "name"field, it will only update the table campain_alert_i18n and not the table campain_i18n, having for effect not to be able to access the name field value from the parent.

kufi commented May 19, 2014

I created a fix for our project in the ConcreteInheritanceParentBehavior.

I overwrote the addObjectGetSyncParent-method (copy-paste the existing method body) and added the following codesnippet to it, just before the "return $parent" line.

    $i18nBehavior = $this->getParentTable()->getBehavior('i18n');
    if($i18nBehavior != null)
        $i18nColumns = preg_split('/,/', $i18nBehavior->getParameter('i18n_columns'));
        $i18nMethod = 'get'.str_replace('%PHPNAME%', $this->getTable()->getName(), $i18nBehavior->getParameter('i18n_phpname')).'s';

        $script .= "
foreach(\$this->".$i18nMethod."() as \$i18n) {
    \$translation = \$parent->getTranslation(\$i18n->getLocale());";

        foreach($i18nColumns as $column)
            $script .= "

        $script .= "
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment