[FLOW3-general] FLOW3 Model
Andrew Leschinsky
andrew at leschinsky.com
Mon Sep 17 19:41:28 CEST 2012
Hi Arnaud,
Yes, it is normal. The collection field is php-only - it is not stored in
the database, and is calculated instead (it's basically select * from
dependant_table where foreign_key = primary_table_id).
You may want to read on Doctrine associations here:
http://docs.doctrine-project.org/en/2.0.x/reference/association-mapping.html
Cheers,
Andrew
On Mon, Sep 17, 2012 at 7:33 PM, Arnaud BECKER <arnobeck at sdv.fr> wrote:
> 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;
> }
>
> }
> ?>
>
>
> _______________________________________________
> FLOW3-general mailing list
> FLOW3-general at lists.typo3.org
> http://lists.typo3.org/cgi-bin/mailman/listinfo/flow3-general
>
More information about the FLOW3-general
mailing list