Note that there are some explanatory texts on larger screens.

plurals
  1. POSonata Admin Collection with sort and delete
    text
    copied!<p>I'm trying to use a <code>sonata_type_collection</code> field for a list of ingredients associated to recipes. Running into two issues:</p> <ol> <li><p>The sortable parameter works for drag/drop re-ordering, but I can't get the items in the association to actually sort by that column.</p></li> <li><p>The delete checkbox isn't working for deleting the associations.</p></li> </ol> <p>The association is a <code>ManyToOne</code>, because the reference table has more data than just a simple reference to the Recipe table, otherwise I'd use a <code>ManyToMany</code>.</p> <p>The <code>sortable</code> parameter worked nicely, making the rows draggable, however the list of ingredients isn't <em>sorted</em> by that column. So although it saves the <code>position</code> column as it should, it doesn't actually display them in that order.</p> <p>I tried to find a simple way to hook into the <code>PersistentCollection</code> in order to filter it. I found the <code>matching()</code> function which works, but it doesn't modify the underlying collection, it just retuns back an <code>ArrayCollection</code>. That doesn't work because I can't replace the <code>PersistentCollection</code> with an <code>ArrayCollection</code>.</p> <p>Also the delete function didn't work out of the box. I had to manually override <code>RecipeAdmin::preUpdate($object)</code> and manually remove the deleted ingredients and flush the Entity Manager.</p> <p>I feel like there should be a much simpler way to do all this.</p> <p>UPDATE: I discovered the <code>@OrderBy</code> annotation today which solves the sorting issue</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload