Development

#6793 (sfFormDoctrine::embedI18n() pk's unset is hard-coded)

You must first sign up to be able to contribute.

Ticket #6793 (closed defect: fixed)

Opened 7 months ago

Last modified 2 months ago

sfFormDoctrine::embedI18n() pk's unset is hard-coded

Reported by: mikael.randy Assigned to: Jonathan.Wage
Priority: major Milestone:
Component: sfDoctrinePlugin Version: 1.2.7
Keywords: form, embedI18n, primary key Cc:
Qualification: Unreviewed

Description

Hello

I have found a defect in sfDoctrinePlugin, in the i18n form embedding.

To start, few general :

Unlike standard embedding, i18n embeddign must have to unset duplicate fields between standard form and i18n one, like primary key and culture field.

With Doctrine, I18n table are created with the "i18n" behavior. By default, primary key is "id" field and culture field is "lang". But, we can configure this and, per exemple, change "id" to "id_foobar" for the pk.

Now, the defect

After define a table, with the "i18n" behavior, and change "id" pk field name, embed a i18n form in parent form with the sfFormDoctrine::embedI18n() method, i always get an errors on validation of 'id' field.

This error due to sfFormDoctrine::embedI18n() method. In this one, we can read this :

$i18nObject = $this->object->Translation[$culture];
$i18n = new $class($i18nObject);
unset($i18n['id'], $i18n['lang']);

You certainly understand why this error appears : pk and culture field are hard coded.

My patch

I have right a correction for this deffect. I now give it to you for validation. I have discover DoctrineTable? have a getIdentifier() method who return all column of pk. So, i have modified sfFormDoctrine::embedI18n() to unset all pk fields of the translate table.

$i18nObject = $this->object->Translation[$culture];
$i18n = new $class($i18nObject);

// Unset all pks of i18n embeded form who are already defines in parent form
foreach( (array) Doctrine::getTable($i18n->getModelName())->getIdentifier() as $column )
{
  unset($this[$column]);
}

Regarding to Doctrine::getTable($i18n->getModelName())->getIdentifier() (getting all fields of the pk), i have originaly found a sfDoctrineRecord::getPrimaryKey(), but i have not understand i $i18n is an instance of a child of this sfDoctrineRecord class, and the return end($identifier) tell me this method just return last field of the pk, and not the entires pk. So, i you have a better way to this getting, i will be ok.

I join my patch to this ticket

Attachments

sfFormDoctrine.class.php.patch (0.7 kB) - added by mikael.randy on 07/08/09 17:27:05.
patch to add my correction

Change History

07/08/09 17:27:05 changed by mikael.randy

  • attachment sfFormDoctrine.class.php.patch added.

patch to add my correction

08/18/09 16:57:38 changed by tyx

This patch works for me as I have the same problem.

Thanks.

11/30/09 21:49:42 changed by Jonathan.Wage

  • status changed from new to closed.
  • resolution set to fixed.

This was already fixed.

The Sensio Labs Network

Since 1998, Sensio Labs has been promoting the Open-Source software movement by providing quality web application development, training, consulting.
Sensio Labs also supports several large Open-Source projects.