sea-orm icon indicating copy to clipboard operation
sea-orm copied to clipboard

Field name 'is_2fa' converted to 'is2fa' during insertion in SeaORM

Open limitcool opened this issue 1 year ago • 3 comments

Description

When generating entity with SeaORM, the insertion statement unexpectedly transforms the field name "is_2fa" into "is2fa".

Steps to Reproduce

  1. The command I executed to generate entity:

sea-orm-cli generate entity --database-url postgres://postgres:password@host:5432/dbname -o src/entity --with-serde both --expanded-format 2.

crate::entity::users::ActiveModel {
        id: Set(Uuid::new_v4()),
        username: Set(username),
        password: Set(util::password::hash(password).await),
        email: Set(email),
        role: Set(crate::entity::sea_orm_active_enums::PermissionLevel::Reader),
        is_2fa: Set(false),
        ..Default::default()
    }
    .insert(&tx)
    .await?;
  1. The SQL generated by SeaORM.
INSERT INTO "users" ("id", "username", "password", "email", "role") VALUES ('2bd3cb70-0b26-4942-9aec-0bc0c37282da', 'admin', '$argon2id$v=19$m=19456,t=2,p=1$lLKmpXeiMihx8esjKmYV3A$ccgd1yniNX6W2b7HSflFic3Z29xuwznsBWqoA9tKrqg', '[email protected]', CAST('reader' AS permission_level)) RETURNING "id", "username", "password", "email", CAST("role" AS text), "email_verified", "is2fa", "avatar_url", "nickname", "gender", "birthday", "country", "region", "bio", "phone_number", "last_login_at", "verification_status", "created_at", "updated_at"

Versions

sea-orm-cli 0.12.14 sea-orm = { version = "0.12.14", features = ["sqlx-postgres", "runtime-tokio-rustls", "macros", "debug-print"] }

limitcool avatar Feb 20 '24 14:02 limitcool

What is your Entity definition?

tyt2y3 avatar Mar 02 '24 12:03 tyt2y3

This is my database model with some fields omitted。

CREATE TABLE "public"."users" (
  "id" uuid NOT NULL,
  "username" text COLLATE "pg_catalog"."default" NOT NULL,
  "password" text COLLATE "pg_catalog"."default" NOT NULL,
  "email" text COLLATE "pg_catalog"."default" NOT NULL,
  "role" "public"."permission_level" NOT NULL,
  "email_verified" bool NOT NULL DEFAULT false,
  "is_2fa" bool NOT NULL DEFAULT false,
  "created_at" timestamptz(6) NOT NULL DEFAULT CURRENT_TIMESTAMP,
  "updated_at" timestamptz(6) NOT NULL DEFAULT CURRENT_TIMESTAMP
)
;

limitcool avatar Mar 02 '24 13:03 limitcool

Thanks, but I mean how the SeaORM entity file look like?

tyt2y3 avatar Mar 02 '24 23:03 tyt2y3