SeaQL / SeaQL/sea-orm

columns with "select_as" attribute are not found and mapped to the model

Open
#1,558 1 comment 0 reactions 1 assignee View on GitHub

@mohs8421 is already working on this.

Since Apr 24, 2023.

Dominant language
Rust
Stars
9.9k
Forks
735
Avg merge
6h 36m
Merged PRs (30d)
8

Description

Description

when trying to use the "select_as" attribute like shown here:

#[derive(Clone, Debug, PartialEq, Eq, DeriveEntityModel)]
#[sea_orm(table_name = "baker")]
pub struct Model {
    #[sea_orm(primary_key)]
    pub id: i32,
    pub name: String,
    pub contact_details: Json,
    #[sea_orm(column_type = "Time", select_as = "CHAR", nullable)]
    pub working_time: Option<String>,
    pub bakery_id: Option<i32>,
}

it will not be possible to actually use the model features for that column, as it will not be properly mapped to the field.
A query generated by that will look like this:

SELECT `baker`.`id`,
        `baker`.`name`, 
        `baker`.`contact_details`,
        CAST(`baker`.`working_time` AS CHAR),
        `baker`.`bakery_id`
FROM `baker`
WHERE `baker`.`id` = 1
LIMIT 1

Steps to Reproduce

  1. Declare a column to select_as something differing
  2. Try to insert into the database (postgres might already fail at this step)
  3. Select the new record from the database and check if the inserted value matches with the expected
Expected Behavior

The query should have an alias for the cast column, the value should be mapped

Actual Behavior

The value does not get mapped

Reproduces How Often

always

Workarounds

This was found while trying to get a workaround to the Time value in use not being able to go higher than 23:59:59.
Would have actually preferred to be able to store a Duration.

Versions

0.11

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.