I've been struggling with some findBy using an entity and I really can't understand what's wrong.
I'm using these two classes:
GPos_Model_Product :
/**
* @Entity
* @Table(name="Product")
*/
class GPos_Model_Product extends GPos_Doctrine_ActiveEntity {
/**
* @Id @Column(type="integer")
* @GeneratedValue
*/
protected $id;
/**
* @ManyToOne(targetEntity="GPos_Model_Store")
* @JoinColumn(name="store_id", referencedColumnName="id")
**/
protected $store;
}
GPos_Model_Store:
/**
* @Entity
* @Table(name="Store")
*/
class GPos_Model_Store extends GPos_Doctrine_ActiveEntity {
/**
* @Id @Column(type="integer")
* @GeneratedValue
*/
protected $id;
/** @Column(name="status", type="string", columnDefinition="enum('active', 'deleted')") */
protected $status = 'active';
}
Note: I've removed useless fields in both class to make it more readable
So here's the problem: In one of my controller I'm trying to retrieve all products that are linked to a certain store:
public function indexAction() {
$this->_helper->getHelper('layout')->disableLayout();
$authNamespace = new Zend_Session_Namespace('Zend_Auth');
//get store's products list.
$store = GPos_Model_Store::find($authNamespace->store);
var_dump($store); //prints store successfully.
//next line throws an unusable exception talking about layout.phtml not found...
$products = GPos_Model_Product::findByStore($store->getId());
//give it to the view for the products list rendering.
var_dump($products);
$this->view->products = $products;
}
Weird enough, when I use $products = GPos_Model_Product::findByStore($store);
instead, I get no exception but simply an empty array as a result.
I used the exact same way (with getId()) in another controller about two other entities that have the same relation and that worked fine.
I checked my DB and the store I'm using as a parameter is indeed bound to a few products which means an empty array as a result isn't correct either. I should retrieve an array of like 8 products...
Here's the code of my other controller that is working fine (narrowed the code again):
$user = GPos_Model_User::findOneByLogin($form->getValue('login'));
$contact = GPos_Model_Contact::findByUser($user->getId());
//these lines work perfectly and I'm receiving an array of `GPos_Model_Contact` entities...
These two pairs of entities are declared in the exact same way so I really don't get it...
Thanks for your help!