一方向の多対1マッピングを持つ2つのエンティティがあります。
ここにあり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);
}
}
ご覧のとおり、$categoriesは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なので、それは行く方法ではないと思います。誰もがそれに対処する方法を知っていますか?
ありがとうございました!