我正在使用带有 Doctrine 的 Symfony 1.2。我有一个带有两种语言翻译的 Place 模型。这个 Place 模型也有一个嵌套的集合行为。
我现在在创建属于另一个节点的新位置时遇到问题。我尝试了两种选择,但都失败了:
1 个选项
$this->mergeForm(new PlaceTranslationForm($this->object->Translation[$lang->getCurrentCulture()]));
如果我合并表单,会发生什么 place_id 字段的值是一个数组。我想是因为它正在等待一个带有 id 的真实对象。如果我尝试设置 place_id='' 则会出现另一个错误。
2个选项
$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
}
}
现在错误是:
Couldn't hydrate. Found non-unique key mapping named 'lang'.
看sql,id没有定义;所以它不能是重复的记录(我有一个唯一的键(id,lang))
知道会发生什么吗?
谢谢!