我有这个实体:
Profile.php
/**
* LoPati'BlogBundle'Entity'Profile
*
* @ORM'Table(name="profile")
* @ORM'Entity
* @Gedmo'TranslationEntity(class="LoPati'BlogBundle'Entity'ProfileTranslation")
*/
class Profile
{
/**
* @ORM'Column(name="id", type="integer")
* @ORM'Id
* @ORM'GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* @Gedmo'Translatable
* @ORM'Column(name="name", type="string", length=255, nullable=true)
*/
protected $name=null;
/**
* @var text $description
* @Gedmo'Translatable
* @ORM'Column(name="description", type="text", nullable=true)
*/
protected $description=null;
/**
* @ORM'OneToMany(targetEntity="ProfileTranslation", mappedBy="object", cascade={"persist", "remove"})
*/
protected $translations;
/**
* Required for Translatable behaviour
* @Gedmo'Locale
*/
protected $locale;
public function __construct()
{
$this->translations = new ArrayCollection;
}
/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}
public function getLocale()
{
return $this->locale;
}
public function setLocale($locale)
{
$this->locale = $locale;
}
public function setName($name)
{
$this->name=$name;
}
public function getName()
{
return $this->name;
}
public function setDescription($description)
{
}
public function getDescription()
{
return $this->description;
}
public function getTranslations()
{
return $this->translations;
}
public function addTranslation(ProfileTranslation $t)
{
$this->translations->add($t);
$t->setObject($this);
$this->name = $this->translations[0];
$this->description = $this->translations[1];
}
public function removeTranslation(ProfileTranslation $t)
{
$this->translations->removeElement($t);
}
public function setTranslations($translations)
{
$this->translations = $translations;
$this->name = $this->translations[0];
$this->description = $this->translations[1];
}
public function __toString()
{
return "hola";
}
}
和ProfileTranslation.php
/**
* @ORM'Entity
* @ORM'Table(name="profile_translations",
* uniqueConstraints={@ORM'UniqueConstraint(name="lookup_unique_idx", columns={
* "locale", "object_id", "field"
* })}
* )
*/
class ProfileTranslation extends AbstractPersonalTranslation
{
/**
* Convinient constructor
*
* @param string $locale
* @param string $field
* @param string $content
*/
public function __construct($locale = null, $field = null, $content = null)
{
$this->setLocale($locale);
$this->setField($field);
$this->setContent($content);
}
/**
* @ORM'ManyToOne(targetEntity="Profile", inversedBy="translations")
* @ORM'JoinColumn(name="object_id", referencedColumnName="id", onDelete="CASCADE")
*/
protected $object;
public function __toString()
{
return $this->getContent();
}
}
我希望在编辑作为ProfileTranslation表的arraycollection时,也更新名称和描述字段,但形成ProfileTable,并且它是该集合的第一个元素。
当我创建新的配置文件时,它可以工作,但当我编辑此配置文件时只更新ProfileTranslation表,而不更新Profile表。
我该怎么做?
您的实现避免了过于经典的可翻译使用。
如果合适的话,你可以看看TranslationFormBundle及其演示。