Skip to content

Children I18n columns not created when using concrete inheritance #510

Open
pimpreneil opened this Issue Nov 19, 2012 · 1 comment

2 participants

@pimpreneil

When using concrete inheritance, it is impossible to use the i18n behavior both in the child and in the parent table.

Example:

<table name="campain" phpName="Campain">
    <column name="name" type="varchar" required="true" primaryString="true" />
    <behavior name="i18n">
        <parameter name="i18n_columns" value="name" />
    </behavior>
</table>

<table name="campain_alert" phpName="CampainAlert">
    <column name="title" type="varchar" required="true" primaryString="true" />

    <behavior name="concrete_inheritance">
        <parameter name="extends" value="campain" />
    </behavior>
    <behavior name="i18n">
        <parameter name="i18n_columns" value="title" />
    </behavior>
</table>

If we generate the tables from the schema above, the campain_alert_i18n will only inherit from its parent's "name" column but won't have its "title" column!

@kufi
kufi commented May 19, 2014

I just stumbled over this error, is this still not fixed?

Anyway, I added a quick workaround in our custom ConcreteInheritanceBehavior class. This should be fleshed out more in a future release, as at the moment any behaviors of the child class get overwritten by the parent class. Instead the behavior should maybe decide itself which parameters to merge, which to use from the parent class and which to use from the child class.

This code basically only fixes the error for the i18n-behavior.

        $copiedBehavior = clone $behavior;
        $copiedBehavior->setTableModified(false);

        //check if child table already has this behavior, then try to merge them
        $existingBehavior = $this->getTable()->getBehavior($behavior->getName());

        //fix for I18n behavior, as it basically overwrites the child columns, instead merge the columns here
        if($existingBehavior != null && $existingBehavior instanceof I18nBehavior)
        {
            $columns = $existingBehavior->getParameter('i18n_columns');

            $existingBehavior->addParameter(array('name' => 'i18n_columns' , 'value' => $columns.','.$copiedBehavior->getParameter('i18n_columns')));
        }
        else
        {
            $this->getTable()->addBehavior($copiedBehavior);
        }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.