단방향 다 대 매핑을 사용하는 엔티티가 두 개 있습니다.Doctrine2 many-to-one 매핑에서 findby
여기 Product
: 당신이 볼 수 있듯이
use Doctrine\Common\Collections\ArrayCollection;
/**
* @Entity
* @Table(name="Product")
* @gedmo:TranslationEntity(class="GPos_Model_Translation_ProductTranslation")
*/
class GPos_Model_Product extends GPos_Doctrine_ActiveEntity {
/**
* @Id @Column(type="integer")
* @GeneratedValue
*/
protected $id;
/**
* @ManyToMany(targetEntity="GPos_Model_Category")
* @JoinTable(name="products_categories",
* joinColumns={@JoinColumn(name="product_id", referencedColumnName="id")},
* inverseJoinColumns={@JoinColumn(name="category_id", referencedColumnName="id")}
* )
*/
protected $categories;
public function __construct() {
$this->categories = new ArrayCollection();
}
public function addCategory(GPos_Model_Category $category) {
if (!$this->categories->contains($category))
$this->categories->add($category);
}
}
은 $ 범주 GPos_Model_Category 엔티티의 ArrayCollection에 있습니다.
이제 어떻게 되나요? 이제 특정 카테고리의 모든 제품과 특정 카테고리의 가 아닌 인 모든 제품을 검색하고 싶습니다.
나는 $products = GPos_Model_Product::findByCategories($category->getId());
을 시도했다 그러나 그것은 단지 나에게
SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '= '1'' at line 1
을주고 $category
의 ID 1은 내가 갈 수있는 방법이 아니다 추측입니다. 누구든지 그 문제를 어떻게 다룰 줄 압니까?
감사합니다.