Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Have you tried something like the following?</p> <p>YAML:</p> <pre><code>Sulu\Bundle\TranslateBundle\Entity\Translation: type: entity table: tr_translations id: code: type: string column: idCodes associationKey: id catalogue: type: string column: idCatalogues associationKey: id fields: value: type: text manyToOne: code: targetEntity: Code cascade: ["persist"] inversedBy: tr_codes joinColumn: name: idCodes referencedColumnName: id catalogue: targetEntity: Catalogue cascade: ["persist"] inversedBy: tr_catalogues joinColumn: name: idCatalogues referencedColumnName: id </code></pre> <p>In your class Translation</p> <pre><code>public function __construct() { $this-&gt;code = new \Doctrine\Common\Collections\ArrayCollection(); $this-&gt;catalogue = new \Doctrine\Common\Collections\ArrayCollection(); } public function addCatalogue($catalogue) { $this-&gt;catalogue[] = $catalogue; return $this; } public function addCode($code) { $this-&gt;code[] = $code; return $this; } </code></pre> <p>Then your code can be something like this:</p> <pre><code>$package = new Package(); $package-&gt;setName($this-&gt;getName()); $catalogue = new Catalogue(); $catalogue-&gt;setLocale($this-&gt;getLocale())-&gt;setPackage($package); $fileCatalogue = $loader-&gt;load($this-&gt;getFile(), $this-&gt;getLocale()); foreach ($fileCatalogue-&gt;all()['messages'] as $key =&gt; $message) { $code = new Code(); $code-&gt;setPackage($package) -&gt;setCode($key) -&gt;setBackend(true) -&gt;setFrontend(true); $translate = new Translation(); $translate-&gt;addCode($code) -&gt;setValue($message) -&gt;addCatalogue($catalogue); $this-&gt;em-&gt;persist($translate); } $this-&gt;em-&gt;flush(); </code></pre> <p>Note: cascade: ["persist"] - Cascades persist operations to the associated entities. <a href="http://docs.doctrine-project.org/en/2.0.x/reference/working-with-associations.html#transitive-persistence-cascade-operations" rel="nofollow">Link</a></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload