The query generated to handle a .find_with_related call does not respect the column_name attribute set in the Model struct: it uses the name derived from the struct field name.
The generated query is the following:
SELECT
`container`.`db_id` AS `A_db_id`,
`content`.`id` AS `B_id`,
`content`.`container_id` AS `B_container_id`
FROM
`container`
LEFT JOIN
`content` ON `container`.`db_id` = `content`.`container_id`
ORDER BY
`container`.`rust_id` ASC
The ORDER BY clause is wrongly generated as we should not get rust_id but db_id. The rest of the query is correctly generated.
Description
Defining a
has_many
relationship when the primary key is a column with acolumn_name
breaks.find_with_related
.Steps to Reproduce
See MWE repository.
Expected Behavior
When I run the query, I expect to retrieve the elements from the database.
Actual Behavior
The query fails with the following message:
Reproduces How Often
It reproduces every-time.
Versions
I am working with MySQL on a debian (not sure if it is relevant for this bug):
Additional Information
The query generated to handle a
.find_with_related
call does not respect thecolumn_name
attribute set in the Model struct: it uses the name derived from the struct field name.The generated query is the following:
The ORDER BY clause is wrongly generated as we should not get
rust_id
butdb_id
. The rest of the query is correctly generated.See https://github.com/bleuse/sea-orm-column-name-bug for a MWE.