I have two entities with a Unidirectional Many-to-One mapping.
Here's 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);
}
}
As you can see, $categories is an ArrayCollection of GPos_Model_Category entities.
Now what? Well now I'd like to retrive all products that are in a given category and also all products that are NOT in a given category.
I've tried $products = GPos_Model_Product::findByCategories($category->getId());
but that only gave me
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
and $category
's ID is 1 so I guess it's not the way to go. Anyone knows how to deal with that ?
Thank you!