Sorun doktrinde 2 ilişkisi haritalama anlamak

0 Cevap php

Ben resmi belgelerine ve konuları ton okumak ama hala benim durum için çözüm bulmuyorum. Benim durum çok temel. Onlar için yorum ve anahtar kelimeler: ben 2 varlıkları var. One comment fazla anahtar kelime olabilir ancak her anahtar kelime yalnızca bir Yorumlarınız için olduğunu. Anahtar kelime tablosunun benzersiz değildir. Yani ben bu bir-çok ilişkisi olduğunu karar verdi. Tablolar yapısı sadece aşağıdaki gibidir:

keywords

id          int(11)
comment_id  int(11)
text        varchar(30)

comments

id      int(11)
text    text

Burada ben onları eşleştirilir nasıl:


/**
 *  @Entity
 *  @Table(name="comments")
 **/
class Comments
{
    /** @Id @Column(type="integer") */
    private $id;
    /** @Column(type="text") */
    private $text;

    /**
     * @OneToMany(targetEntity="keywords", mappedBy="comment_id")
     */
    private $keywords;

    public function getText(){return $this->text;}
    public function getId(){return $this->id;}
    public function getKeywords(){return $this->keywords;}
}
/**
 *  @Entity
 *  @Table(name="keywords")
 */

class Keywords
{
    /** @Id @Column(type="integer") */
    private $id;

    private $text;

    public function getText(){return $this->text;}
    public function getId(){return $this->id;}
}

ve nasıl kullanarak bu gibi:


$comments = $this->em->getRepository('comments' )->findAll();
foreach($comments as $comment){
    foreach($comment->getKeywords() as $keyword){
        $keyword->getText();
    }
}

and got this errors:

Notice: Undefined index: comment_id in C:\web_includes\doctrine\ORM\Persisters\BasicEntityPersister.php on line 1096
Notice: Trying to get property of non-object in C:\web_includes\doctrine\ORM\Persisters\BasicEntityPersister.php on line 1098
Warning: Invalid argument supplied for foreach() in C:\web_includes\doctrine\ORM\Persisters\BasicEntityPersister.php on line 1098
Notice: Undefined index: comment_id in C:\web_includes\doctrine\ORM\PersistentCollection.php on line 168
Fatal error: Call to a member function setValue() on a non-object in C:\web_includes\doctrine\ORM\PersistentCollection.php on line 169
What is wrong? where is should define comment_id? Is my mapping correct? i really stuck and need help so please, any advice are very welcome.

0 Cevap