[FLOW3-general] FLOW3 Model

Arnaud BECKER arnobeck at sdv.fr
Mon Sep 17 18:33:58 CEST 2012


Hello,

I'm starting with FLOW3 1.1.0.

I've created 2 Model "Forum" and "Debat" and Forum contains an array collection of "debats" and "Debat" contains a pointer to the "Forum" it's attached to.

The doctrine:migrationgenerate generate the field "forum" in the table "debat" and the foreign key. But there is no field "debats" or associative in the "forum" table.

Is this normal ? Is the link only done through the "forum" field in the "Debat" table ?

After this, you can find the code for the two models (which have both a repository).

Thanks for your help.
Arnaud


Forum.php -->
<?php
namespace NvlObs\Debats\Domain\Model;

/*                                                                        *
 * This script belongs to the FLOW3 package "NvlObs.Debats".              *
 *                                                                        *
 *                                                                        */

use TYPO3\FLOW3\Annotations as FLOW3;
use Doctrine\ORM\Mapping as ORM;

/**
 * A Forum
 *
 * @FLOW3\Entity
 */
class Forum {

	/**
	 * Le titre
	 * @var string
	 */
	protected $titre;

	
    /**
      * Les débats contenus dans un forum
      *
      * @var \Doctrine\Common\Collections\Collection<\NvlObs\Debats\Domain\Model\Debat>
      * @ORM\OneToMany(mappedBy="forum")
      */
    protected $debats;


	/**
      * Constructs a new Forum
      */
    public function __construct() {
        $this->debats = new \Doctrine\Common\Collections\ArrayCollection();
    }



	/**
	 * Get the Forum's title
	 *
	 * @return string The Forum's title
	 */
	public function getTitre() {
		return $this->titre;
	}

	/**
	 * Sets this Forum's name
	 *
	 * @param string $titre The Forum's name
	 * @return void
	 */
	public function setTitre($titre) {
		$this->titre = $titre;
	}
	
	    /**
         * Adds a post to this blog
         *
         * @param \NvlObs\Debats\Domain\Model\Debat $debat
         * @return void
         */
        public function addDebat(\NvlObs\Debats\Domain\Model\Debat $debat) {
                $debat->setForum($this);
                $this->debats->add($debat);
        }

        /**
         * Removes a post from this blog
         *
         * @param \NvlObs\Debats\Domain\Model\Debat $debat
         * @return void
         */
        public function removeDebat(\NvlObs\Debats\Domain\Model\Debat $debat) {
                $this->debats->removeElement($debat);
        }

}
?>



Debat.php -->
<?php
namespace NvlObs\Debats\Domain\Model;

/*                                                                        *
 * This script belongs to the FLOW3 package "NvlObs.Debats".              *
 *                                                                        *
 *                                                                        */

use TYPO3\FLOW3\Annotations as FLOW3;
use Doctrine\ORM\Mapping as ORM;

/**
 * A Debat
 *
 * @FLOW3\Entity
 */
class Debat {

	/**
	 * Le titre
	 * @var string
	 */
	protected $titre;

	/**
      * Le Forum
      * @var \NvlObs\Debats\Domain\Model\Forum
      * @ORM\ManyToOne(inversedBy="debats")
      */
    protected $forum;


	/**
	 * Get the Debat's name
	 *
	 * @return string The Debat's name
	 */
	public function getTitre() {
		return $this->titre;
	}

	/**
	 * Sets this Debat's name
	 *
	 * @param string $titre The Debat's name
	 * @return void
	 */
	public function setTitre($titre) {
		$this->titre = $titre;
	}
	
	
	
	/**
	 * Get le forum
	 *
	 * @return \NvlObs\Debats\Domain\Model\Forum Le forum
	 */
	public function getForum() {
		return $this->forum;
	}

	/**
	  * Sets le forum
	  *
	  * @param \NvlObs\Debats\Domain\Model\Forum $forum Le forum
	  * @return void
	  */
	public function setForum($forum) {
		$this->forum = $forum;
	}

}
?>




More information about the FLOW3-general mailing list