-
-
Notifications
You must be signed in to change notification settings - Fork 615
Customize column names #79
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
I insist that after we released a new version of sea-orm-macro, we bump the dependency and remove the |
I noticed that it used path also, wasn't sure if it was a mistake or not. This is awesome, you guys work so fast. Is there any examples of how to use this feature to rename columns? |
|
sea-orm/src/tests_cfg/filling.rs Lines 19 to 34 in 8b30ef7
|
|
Oh I see, didn't go with an attribute? Like: #[derive(Copy, Clone, Debug, EnumIter, DeriveColumn)]
pub enum Column {
#[sea(rename = "id")]
Id,
#[sea(rename = "full_name")]
Name,
} |
|
We want to keep it simple and avoid using excessive macros loll |
|
Though, I think we can also have fallback: impl IdenStatic for Column {
// the default impl is self.default_as_str()
fn as_str(&self) -> &str {
match self {
Self::Id => "_id",
_ => self.default_as_str(),
}
}
} |
|
Ohh okay I see 😄 Serde uses a macro for renaming, but I guess the |
|
SeaORM tries to avoid custom macro syntax. I think it was our principle to make things runtime-configurable. |
|
Does the renaming also need to be implemented for For example, how do we rename columns here: sea-orm/src/tests_cfg/filling.rs Lines 13 to 17 in 8b30ef7
|
|
Our assumption on naming model attributes & column enum variants:
So, that means if you want to rename one of the attribute / column you have to also update the other half of it. |
|
I'm still a little confused, for the column you would rename it with |
|
So basically the Take your example in #76... we might do the followings #[derive(Clone, Debug, PartialEq, DeriveModel, DeriveActiveModel)]
pub struct Model {
pub id: i32,
pub type_of: String,
}
#[derive(Copy, Clone, Debug, EnumIter, DeriveCustomColumn)]
pub enum Column {
Id,
TypeOf,
}
impl IdenStatic for Column {
fn as_str(&self) -> &str {
match self {
Self::TypeOf => "type",
_ => self.default_as_str(),
}
}
} |
|
Ah perfect, it all makes sense now thank you @billy1624 ... again XD !!! |
Resolve #43