I’d like to have an array of arrays in a class using Zend and Doctrine2.
So I have a class named Grid, which should have an attribute containing an array of arrays of GridItem. These GridItem‘s also containing a link to an instance of Product.
Here’s Grid.php:
/**
* @Entity
* @Table(name="Grid")
*/
class GPos_Model_Grid extends GPos_Doctrine_ActiveEntity {
/**
* @Id @Column(type="integer")
* @GeneratedValue
*/
private $id;
/** @Column(type="integer") */
private $number;
//THIS IS THE ATTRIBUTE
private $grid;
}
And here’s GridItem.php:
/**
* @Entity
* @Table(name="GridItem")
*/
class GPos_Model_GridItem extends GPos_Doctrine_ActiveEntity {
/**
* @Id @Column(type="integer")
* @GeneratedValue
*/
private $id;
/** @Column(length=7) */
private $color;
/** @Column(type="boolean") */
private $grid;
/**
* @ManyToOne(targetEntity="Product")
* @JoinColumn(name="product_id", referencedColumnName="id")
*/
private $product;
}
So as I said, I’d like the $grid attribute to be stored as an ArrayCollection of ArrayCollections of GridItem.
However, I can’t figure out what annotation I should use to make this happen. The only way I found right now is to create a middle class between Grid and GridItem that would be something like GridRow. So I could have Many-To-One associations between all of them. But this produces a new ‘joint’ between tables and I’d have a small but still significant performance hit which I can’t afford.
Do you guys have any advice on how to do this without that GridRow class ? Thus using only Grid and GridItem ?
Thank you for helping me!
I finally opted for the
GridRowoption as I found no way of storing arrays of arrays..