views:

990

answers:

1

Hi,

I'm using Symfony 1.2 with Doctrine. I have a Place model with translations in two languages. This Place model has also a nested set behaviour.

I'm having problems now creating a new place that belongs to another node. I've tried two options but both of them fail:

1 option

    $this->mergeForm(new PlaceTranslationForm($this->object->Translation[$lang->getCurrentCulture()]));

If I merge the form, what happens is that the value of the place_id field id an array. I suppose is because it is waiting a real object with an id. If I try to set place_id='' there is another error.

2 option

$this->mergeI18n(array($lang->getCurrentCulture()));

public function mergeI18n($cultures, $decorator = null)
{
if (!$this->isI18n())
{
      throw new sfException(sprintf('The model "%s" is not internationalized.', $this->getModelName()));
}

$class = $this->getI18nFormClass();
foreach ($cultures as $culture)
{
      $i18nObject = $this->object->Translation[$culture];
      $i18n = new $class($i18nObject);
      unset($i18n['id']);
   $i18n->widgetSchema['lang'] = new sfWidgetFormInputHidden(); 

      $this->mergeForm($i18n); // pass $culture too
}
}

Now the error is:

Couldn't hydrate. Found non-unique key mapping named 'lang'.

Looking at the sql, the id is not defined; so it can't be a duplicate record (I have a unique key (id, lang))

Any idea of what can be happening?

thanks!

A: 

It looks like the issues you are having are related to embedding forms within each other, which can be tricky. You will likely need to do things in the updateObject/bind methods of the parent form to get it to pass its values correctly to its child forms.

This article is worth a read:

http://www.blogs.uni-osnabrueck.de/rotapken/2009/03/13/symfony-merge-embedded-form/comment-page-1/

It gives some good info on how embedding (and mergeing) forms work. The technique the article uses will probably work for you, but I've not used I18n in sf before, so it may well be that there is a more elegant solution built in?

benlumley