Open naskya opened 8 months ago
I also encountered the same problem
sea-orm-cli generate entity -o entity/src -l -u postgres://postgres:postgres@localhost:22732/postgres
--with-serde both
--model-extra-attributes='graphql(concrete(name = "Favorite",params()))'
--model-extra-derives async_graphql::SimpleObject
result
yexiyue@wisteriadeMacBook-Pro graphql-study % sea-orm-cli generate entity -o entity/src -l -u postgres://postgres:postgres@localhost:22732/postgres --with-serde both --model-extra-attributes='graphql(concrete(name = "Favorite",params()))' --model-extra-derives async_graphql::SimpleObject
Connecting to Postgres ...
Discovering schema ...
... discovered.
thread 'main' panicked at /Users/yexiyue/.cargo/registry/src/mirrors.sjtug.sjtu.edu.cn-be2141875385cea5/sea-orm-codegen-0.12.14/src/entity/writer.rs:108:57:
called `Result::unwrap()` on an `Err` value: LexError { span: Span }
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
However, there are still spaces in front, which is not very aesthetically pleasing
//! `SeaORM` Entity. Generated by sea-orm-codegen 0.12.14
use sea_orm::entity::prelude::*;
use serde::{Deserialize, Serialize};
#[derive(
Clone,
Debug,
PartialEq,
DeriveEntityModel,
Eq,
Serialize,
Deserialize,
async_graphql :: SimpleObject,
)]
#[sea_orm(table_name = "favorite")]
#[graphql(concrete(name = "Favorite"params()))]
pub struct Model {
#[sea_orm(primary_key, auto_increment = false)]
pub user_id: i32,
#[sea_orm(primary_key, auto_increment = false)]
pub action_id: i32,
pub create_time: Option<DateTime>,
}
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
pub enum Relation {
#[sea_orm(
belongs_to = "super::actions::Entity",
from = "Column::ActionId",
to = "super::actions::Column::Id",
on_update = "Cascade",
on_delete = "Cascade"
)]
Actions,
#[sea_orm(
belongs_to = "super::user::Entity",
from = "Column::UserId",
to = "super::user::Column::Id",
on_update = "Cascade",
on_delete = "Cascade"
)]
User,
}
impl Related<super::actions::Entity> for Entity {
fn to() -> RelationDef {
Relation::Actions.def()
}
}
impl Related<super::user::Entity> for Entity {
fn to() -> RelationDef {
Relation::User.def()
}
}
impl ActiveModelBehavior for ActiveModel {}
I also encountered the same problem
sea-orm-cli generate entity -o entity/src -l -u postgres://postgres:postgres@localhost:22732/postgres --with-serde both --model-extra-attributes='graphql(concrete(name = "Favorite",params()))' --model-extra-derives async_graphql::SimpleObject
result
yexiyue@wisteriadeMacBook-Pro graphql-study % sea-orm-cli generate entity -o entity/src -l -u postgres://postgres:postgres@localhost:22732/postgres --with-serde both --model-extra-attributes='graphql(concrete(name = "Favorite",params()))' --model-extra-derives async_graphql::SimpleObject Connecting to Postgres ... Discovering schema ... ... discovered. thread 'main' panicked at /Users/yexiyue/.cargo/registry/src/mirrors.sjtug.sjtu.edu.cn-be2141875385cea5/sea-orm-codegen-0.12.14/src/entity/writer.rs:108:57: called `Result::unwrap()` on an `Err` value: LexError { span: Span } note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
When I remove the comma before params, it can work properly
However, there are still spaces in front, which is not very aesthetically pleasing
//! `SeaORM` Entity. Generated by sea-orm-codegen 0.12.14 use sea_orm::entity::prelude::*; use serde::{Deserialize, Serialize}; #[derive( Clone, Debug, PartialEq, DeriveEntityModel, Eq, Serialize, Deserialize, async_graphql :: SimpleObject, )] #[sea_orm(table_name = "favorite")] #[graphql(concrete(name = "Favorite"params()))] pub struct Model { #[sea_orm(primary_key, auto_increment = false)] pub user_id: i32, #[sea_orm(primary_key, auto_increment = false)] pub action_id: i32, pub create_time: Option<DateTime>, } #[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)] pub enum Relation { #[sea_orm( belongs_to = "super::actions::Entity", from = "Column::ActionId", to = "super::actions::Column::Id", on_update = "Cascade", on_delete = "Cascade" )] Actions, #[sea_orm( belongs_to = "super::user::Entity", from = "Column::UserId", to = "super::user::Column::Id", on_update = "Cascade", on_delete = "Cascade" )] User, } impl Related<super::actions::Entity> for Entity { fn to() -> RelationDef { Relation::Actions.def() } } impl Related<super::user::Entity> for Entity { fn to() -> RelationDef { Relation::User.def() } } impl ActiveModelBehavior for ActiveModel {}
Removing the comma also doesn't allow the generated code to be compiled
Description
We can't seem to pass a string containing a comma surrounded by parentheses as
model-extra-attributes
in sea-orm-cli. This becomes a problem when you want to passcfg_attr(predicate, attribute)
, for instance.Steps to Reproduce
Expected Behavior
Since the following does work and produces
Model
s with#[test(a)]
, I guesstest(a, b)
should also work.Actual Behavior
Reproduces How Often
This is always reproducible.
Workarounds
There's no workaround as far as I'm aware (except manual string processing for generated entities)
Reproducible Example
Versions