Hi all. i hope you can help me.
I am working with doctrineextensions nestedset. i am trying to build a
multilingual tree.
I created 2 entities:
- Node (the tree, type nested. Has one-to-many relation with
NodeContent  )
- NodeContent (contains node translations. It should have a reference
to the node id)

All data are correctly inserted in the tables except the relation id
when i persist an object from the controller (null value is inserted).
I don't understand what is wrong because onetomany relation works
without using tree extension.
I thiink creating a multilingual tree bundle would be very useful :)

Thanks!!



This is my controller:

/******************************* Controller
***************************************/
..
$newNode = new Node();
$parentNode = $node->findOneById(str_replace('item_', '', $parentId));
$newNode->setTitle($title);
$newNode->setParent($parentNode);

$languages = array('it','en','fr');
foreach($languages as $language){
        $newNodeContent = new NodeContent();
        $newNodeContent->setLanguage($language);
        $newNodeContent->setTitle($title.'_'.$language);
        $newNode->addNodeContent($newNodeContent);
}
$em->persist($newNode);
$em->flush();
...

And these are the classes:


/******************************* Node
***************************************/


use Gedmo\Mapping\Annotation as Gedmo;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM;

/**
 * @Gedmo\Tree(type="nested")
 * @ORM\Table(name="node")
 * use repository for handy tree functions
 * @ORM\Entity(repositoryClass="Gedmo\Tree\Entity\Repository
\NestedTreeRepository")
 */
class Node
{
    /**
     * @ORM\Id
     * @ORM\Column(type="integer")
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    protected $id;

    /**
     * @ORM\Column(type="string")
     */
    protected $title;

    /**
    * @Gedmo\TreeLeft
    * @ORM\Column(name="lft", type="integer")
    */
    private $lft;

    /**
     * @Gedmo\TreeLevel
     * @ORM\Column(name="lvl", type="integer")
     */
    private $lvl;

    /**
     * @Gedmo\TreeRight
     * @ORM\Column(name="rgt", type="integer")
     */
    private $rgt;

    /**
     * @Gedmo\TreeRoot
     * @ORM\Column(name="root", type="integer", nullable=true)
     */
    private $root;

    /**
     * @Gedmo\TreeParent
     * @ORM\ManyToOne(targetEntity="Node", inversedBy="children")
     * @ORM\JoinColumn(name="parent_id", referencedColumnName="id",
onDelete="SET NULL")
     */
    private $parent;

    /**
     * @ORM\OneToMany(targetEntity="Node", mappedBy="parent")
     * @ORM\OrderBy({"lft" = "ASC"})
     */
    private $children;

    /**
     * @ORM\OneToMany(targetEntity="NodeContent", mappedBy="node",
cascade={"persist"})
     * @ORM\OrderBy({"language" = "DESC"})
     *
     * @var ArrayCollection $nodecontents
     */
    protected $nodecontents;

    /**
    * @ORM\Column(type="datetime")
    */
    protected $created;

    /**
     * @ORM\Column(type="datetime")
     */
    protected $updated;


    public function __construct()
    {
        $this->children = new \Doctrine\Common\Collections
\ArrayCollection();
        $this->nodecontents = new ArrayCollection();

        $this->setCreated(new \DateTime());
        $this->setUpdated(new \DateTime());
    }
....

/******************************* NodeContent
***************************************/

use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Mapping\ClassMetadata;
use Symfony\Component\Validator\Constraints\NotBlank;

/**
 * @ORM\Entity(repositoryClass="Acme\PageBundle\Repository
\NodeContentRepository")
 * @ORM\Table(name="node_content")
 * @ORM\HasLifecycleCallbacks()
 */
class NodeContent
{
    /**
     * @ORM\Id
     * @ORM\Column(type="integer")
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    protected $id;

    /**
    * @ORM\Column(type="string", length=2)
    */
    protected $language;

    /**
     * @ORM\ManyToOne(targetEntity="Node", inversedBy="nodecontents")
     * @ORM\JoinColumn(name="node_id", referencedColumnName="id")
     *
     * @var Node $node
     */
    protected $node;

    public function __construct()
    {

    }

...

-- 
If you want to report a vulnerability issue on symfony, please send it to 
security at symfony-project.com

You received this message because you are subscribed to the Google
Groups "symfony developers" group.
To post to this group, send email to symfony-devs@googlegroups.com
To unsubscribe from this group, send email to
symfony-devs+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/symfony-devs?hl=en

Reply via email to