Description
As per the latest documentation, the only way to order a many-to-many association is according to a field in the target entity:
@OrderBy({"name" = "ASC"})
Sometimes however, one might want to have a many-to-many association with a custom order. For example, I'm creating a Newsletter
that targets a number of Deal
s. My deals are ordered differently in every newsletter, as picked by the administrator authoring the newsletter.
So it would be nice if I could just add()
my Deals to my many-to-many Collection, and next time I retrieve the Newsletter entity, it would just reload the Deals in the same order.
Under the hood, the many-to-many table could have an extra position
field, that would transparently be used to order the collection.
As far as I know, there is currently no way to achieve this. I have to create an intermediate NewsletterDeal
entity that contains the Newsletter, the Deal and the position, and use a one-to-many association ordered by position.
It's OK, but it's an extra burden that could be avoided.
Would you guys be OK on the principle to add this feature? In which case, I'd be happy to give it a try and submit a PR.