-
Notifications
You must be signed in to change notification settings - Fork 30
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Documentation request -- how to orderBy on an embeddable object #33
Comments
Hi Jack, First let me point you to a fork of this project for ORM only: https://github.com/API-Skeletons/zf-doctrine-orm-querybuilder I did this yesterday but all the tests are passing. Still another set of eyes would be welcome. You can specify an alias e.g. https://github.com/API-Skeletons/zf-doctrine-orm-querybuilder/blob/master/src/OrderBy/FieldOrderBy.php#L16 but I don't think that's what you're going for. I think you have a function on your entity called The Doctrine QueryBuilder is used to create DQL which is transpiled to SQL. If you cannot get the value through SQL then you can't get it through DQL. Notice your error says no field or association. This is correct. |
Okay, so I've narrowed this down a little bit and I think the issue is just with the orderBy tidbits. Example that works in query string (provides results w/ an amount > 2500): What doesn't work is sorting on the field's order-by. That yields the semantical error. Below is the DQL that is generated when using priceObj.amount as the 'field'. |
You can't use ANYTHING.anyfield. You have to use 'alias': On Wed, Aug 3, 2016 at 11:25 AM Jack Peterson [email protected]
|
After trying various forms of aliasing (specifying in the filter options, setting the setting the object I'm pulling in as 'row') as well as attempting directly creating the DQL through query Builder ... I think I'm coming to the conclusion that one cannot perform an order-by operation on an embeddable's field value. If I create a query directly using DQL ... it works ... but using querybuilder to do so ... not so much. Any thoughts would be much appreciated. http://pastie.org/pastes/10929903/text?key=nqyfrbl53ot75hg0fqvg is the pastie where I have the entity and the value object defined as well as some additional info related to this. |
This is not a problem with this module, rather it's an issue with doctrine and MySQL 5.7: |
How would one perform a sort operation on a collection where the entity has an embeddable value object?
e.g., let's assume we have a currency object in there with a field, "amount" that's an integer.
&order-by[0][field]=priceObj_amount&order-by[0][direction]=desc
returns a semantical error, like:
"detail": "[Semantical Error] line 0, col 138 near 'priceObj_amount': Error: Class Example\Entity\Barcode\Item has no field or association named priceObj_amount",
The text was updated successfully, but these errors were encountered: