doctrine - Symfony: Ordered one-to-many relationship -


i have 2 separate entities want link one-to-many relationship. want relationship ordered, meaning every time call on first entity, elements of second entity come in pre-ordered way. cannot use 'order by' calls because order has nothing fields of second entity. thought having 1 field of first entity array of entities, i'm not sure how accomplish either..

edit

so far have this:

/**  * @orm\onetomany(targetentity="fusiondesign\blogbundle\entity\element", mappedby="page")  */ private $elements; 

and

/**  * @orm\manytoone(targetentity="fusiondesign\blogbundle\entity\page", inversedby="elements")  * @orm\joincolumn(name="page_id", referencedcolumnname="id")  */ private $page; 

i'm aware can put "order whatever asc" somewhere in there orders according column in element, , that's not need, because element entities , page entities never persisted @ same time, nor same process. want constructing basic cms user generate new pages. first choose kind of elements page potentially have (like header image, banner, title, , on) , persist element entities fields describing html, routing , controller content according choices. then, when new page created, give user choice order potential elements @ will, , bind element entities following order reflects layout desired.

i thought having this

/**  * @var array  *  * @orm\column(name="structure", type="array")  */ private $structure; 

where array stores element entities have no idea how that.

you need define orderby attribute in doctrine's mapping configuration relation.

yaml mapping example:

'example\entity\article':   # [..]   onetomany:     images:       targetentity: 'example\entity\article\image\articleimage'       mappedby: 'article'       orderby:   # <--- here         position: 'asc' 

Comments

Popular posts from this blog

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

python Tkinter Capturing keyboard events save as one single string -

sql server - Why does Linq-to-SQL add unnecessary COUNT()? -