Closed jackdpeterson closed 8 years ago
Expected:
SELECT b0_.id AS id_0, b0_.feedProvider AS feedProvider_1, b0_.isNew AS isNew_2, b0_.title AS title_3, b0_.description AS description_4, b0_.GSIN AS GSIN_5, b0_.createdAt AS createdAt_6, b0_.url AS url_7, b0_.imageUrl AS imageUrl_8, b0_.fpExtendedAttributes AS fpExtendedAttributes_9, b0_.priceObj_amount AS priceObj_amount_10, b0_.priceObj_currencyCode AS priceObj_currencyCode_11, b0_.location_latitude AS location_latitude_12, b0_.location_longitude AS location_longitude_13 FROM barcode_product_result b0_ WHERE b0_.GSIN = ? AND b0_.isNew = ? AND b0_.priceObj_amount >= ? ORDER BY priceObj_amount_10 ASC
Actual:
SELECT b0_.id AS id_0, b0_.feedProvider AS feedProvider_1, b0_.isNew AS isNew_2, b0_.title AS title_3, b0_.description AS description_4, b0_.GSIN AS GSIN_5, b0_.createdAt AS createdAt_6, b0_.url AS url_7, b0_.imageUrl AS imageUrl_8, b0_.fpExtendedAttributes AS fpExtendedAttributes_9, b0_.priceObj_amount AS priceObj_amount_10, b0_.priceObj_currencyCode AS priceObj_currencyCode_11, b0_.location_latitude AS location_latitude_12, b0_.location_longitude AS location_longitude_13 FROM barcode_product_result b0_ WHERE b0_.GSIN = ? AND b0_.isNew = ? AND b0_.priceObj_amount >= ? ORDER BY b0_.priceObj_amount ASC
The key difference is that "b0.priceObj_amount" should become "priceObj_amount_10" according to the "OriginalFieldName" As "Re-mappedName"
As mentioned on IRC, might be worth looking into https://github.com/doctrine/doctrine2/blob/31a0c02b066764ec7b55eedc5f3cab78235a4e4b/lib/Doctrine/ORM/Query/SqlWalker.php#L330 and code around it, which is responsible for alias generation.
This seems to be a duplicate / slightly different version of the same issues described in #5622. After modifying my entity to not use a value object and just do simple sorting ... this issue (albeit outside of an embeddable) remains.
I can confirm that setting
[mysqld]
sql-mode= "STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"
Does resolve this issue.
If one has an entity that contains an embeddable (referenced as $priceObj):
And one attempts to perform an orderBy on the amount field. Doctrine generates a proper-looking DQL statement; however, the SQL statement where the order-by'd element is using the pre-aliased select statement. This appears to cause a 'semantical error'.
PHP:
Generated DQL:
Generated SQL:
$ php composer.phar show --installed | grep doctrine