1

i am using the latest version of doctrine: 2.3

when you call a generated association function, the first time everything is fine:

$authors = $book->getBookToAuthors();
//$authors = array(5)

but the second time instead of returning the array of all associations it returns the last hydrated entity:

$authors = $book->getBookToAuthors();
//$authors = BookToAuthor entity

that happens even when there is nothing else happening:

$authors = $book->getBookToAuthors(); //will work
$authors = $book->getBookToAuthors(); //won't work

the function of getBookToAuthors() is:

public function getBookToAuthors()
{
    return $this->bookToAuthors;
}

and the mapping is as follows:

/**
 * @var BookToAuthor[]
 *
 * @OneToMany(targetEntity="BookToAuthor", mappedBy="book", cascade={"persist"})
 * @JoinColumn(name="id", referencedColumnName="book_id", onDelete="cascade")
 */
private $bookToAuthors;

please advise. i don't know what to do... :-(

4

1 回答 1

1

对不起对不起,这是关联目标方面的错误。目标具有一对一关联而不是多对一

如果您遇到此问题,请确保双方的关联类型匹配

于 2012-10-15T15:04:58.137 回答