我的問題是密切相關的這一個Undefined index: inverseJoinColumns while trying to define ManyToMany relationship between two entities主義N:M關係未定義指數:joinColumns在BasicEntityPersister.php
我試圖找到所有這些都沒有部分書籍。 - > findBy(陣列( 「部分」=>空)
這是我的實體的配置: EditedBooks
/**
* @var \Doctrine\Common\Collections\Collection
*
* @ORM\ManyToMany(targetEntity="Sections", inversedBy="editedBook")
* @ORM\JoinTable(name="edited_book_has_section",
* joinColumns={
* @ORM\JoinColumn(name="edited_book_id", referencedColumnName="id")
* },
* inverseJoinColumns={
* @ORM\JoinColumn(name="section_id", referencedColumnName="id")
* }
*)
*/
private $section;
這是我的實體的配置: 節
/**
* Bidirectional (INVERSE SIDE)
*
* @ORM\ManyToMany(targetEntity="EditedBooks", mappedBy="section")
*/
private $editedBook;
我收到的錯誤
Undefined index: joinColumns in BasicEntityPersister.php
我tryied也只有
/**
* @var \Doctrine\Common\Collections\Collection
*
* @ORM\ManyToMany(targetEntity="Sections", inversedBy="editedBook")
* @ORM\JoinTable(name="edited_book_has_section")
*/
或切換的定義,但後來我收到此錯誤
You cannot search for the association field '\Entity\EditedBooks#section', because it is the inverse side of an association. Find methods only work on owning side associations.
解決方法: 今天我試圖解決我的問題,在QueryBuilder的我editedbooksRepository
$query = $qb->select('books')
->from('Bundle:EditedBooks', 'books')
->leftJoin('books.section', 'sec')
->addSelect('COUNT(sec.id) AS sec_count')
->andWhere('sec_count = 0');
但是我receved以下錯誤:
An exception occurred while executing 'SELECT e0_.id AS id0, e0_.doi AS doi1, e0_.isbn_print AS isbn_print2, e0_.isbn_electronic AS isbn_electronic3, e0_.publication_date AS publication_date4, e0_.price_print AS price_print5, e0_.price_electronic AS price_electronic6, e0_.summary AS summary7, e0_.title AS title8, e0_.ongoing AS ongoing9, e0_.pages AS pages10, e0_.illustrations AS illustrations11, e0_.entry_date AS entry_date12, e0_.google_id AS google_id13, e0_.specialIssue_comment AS specialIssue_comment14, e0_.deleted AS deleted15, e0_.specialIssue_id AS specialIssue_id16, COUNT(s1_.id) AS sclr17, e0_.book_series_id AS book_series_id18, e0_.copyright_id AS copyright_id19, e0_.publisher_id AS publisher_id20 FROM edited_books e0_ LEFT JOIN edited_book_has_section e2_ ON e0_.id = e2_.editedbooks_id LEFT JOIN sections s1_ ON s1_.id = e2_.sections_id WHERE sclr17 = 0':
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'sclr17' in 'where clause'
但對我來說好像sclr17存在,我失去的東西嗎?
醜陋的解決方法 我知道這是不應該做的事情,但有時一個人有一個人必須做什麼:
$noSection = new Sections();
$noSection->setTitle("Sectionless");
//add all the books
$noSection->setEditedBook(new ArrayCollection($books));
//remove the assigned ones
foreach($sections as $section){
$sBooks = $section->getEditedBook();
foreach($sBooks as $b){
$noSection->removeEditedBook($b);
}
}
隨着髒修復它現在的工作,但我很高興爲任何其他解決方案。
找到了答案? – Abstract 2014-10-03 23:44:11