Replies: 10 comments
-
|
Yes, I think I think a major concern is whether we can apply the same operation to partial and custom selects. What do you think about this? |
Beta Was this translation helpful? Give feedback.
-
|
Thank you for your reply. There is such a scenario. Suppose we have a user table: Here, the status column is a state column. Our design principle is to store values like This translation operation is just one example of similar cases. Moreover, this translation operation cannot be hard-coded into select because it is dynamic and stored in the database. During translation, it dynamically queries the database based on relevant identifiers to obtain translated content corresponding to |
Beta Was this translation helpful? Give feedback.
-
|
Of course, the user's status is just a simple example. Perhaps you might think that it can be hard-coded because enabling and disabling are basically determined in the future. But what about the user's type? Suppose the user has a What if a new type, |
Beta Was this translation helpful? Give feedback.
-
|
If we only focus on your use case, I'd think the "after select" operation can be per column, do you have a need for it to access all fields of the model in one call? I am thinking a definition of: fn after_select(column: E::Column, value: Value) -> Value;
// or ?
fn after_select(&mut E::Model); |
Beta Was this translation helpful? Give feedback.
-
|
I think: fn after_select(&mut E::Model);would be better. The reasons are as follows: More customized modifications can be made to the model. Scenario 1: The modification of a certain field depends on several other fields in the model. #[derive(
Clone, Debug, PartialEq, Eq, DeriveEntityModel, Serialize, Deserialize, DataDictionaryTranslate,
)]
#[sea_orm(table_name = "sys_user")]
#[serde(rename_all = "camelCase")]
pub struct Model {
#[sea_orm(primary_key, auto_increment = false)]
pub id: String,
// ... other omitted fields
#[translate(name = "user_status", field = "status_name")]
pub status: SwitchStatus,
#[sea_orm(ignore)]
pub status_name: Option<String>,
}For the field If fn after_select(model &mut E::Model) {
// 1. Directly call the method derived from the custom `Derive` macro `DataDictionaryTranslate`.
model.translate();
// 2. Or manually translate
model.status_name = translate_data_dictionary("user_status", model.status);
} |
Beta Was this translation helpful? Give feedback.
-
|
I do agree that adding a new method to the trait I was looking into the implementation strategy, but realized quite a bit of plumbing work needs to be done to carry the It would be easier if we attach the behaviour onto |
Beta Was this translation helpful? Give feedback.
-
|
Thank you. I am a Java programmer and only a beginner in Rust. I apologize that I cannot thoroughly understand the sea-orm source code in a short period of time, so I cannot provide some reasonable implementation strategy suggestions. |
Beta Was this translation helpful? Give feedback.
-
|
Okay, have another idea. If we allow ourselves to |
Beta Was this translation helpful? Give feedback.
-
|
This is a way to make SeaOrm work like PaperTrail in ruby? |
Beta Was this translation helpful? Give feedback.
-
|
I'm realy interested in make papertrail-style lib for sea_orm. Automatically audition. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Motivation
Many times, our table structure will have fields like:
created_at,updated_at,created_by,updated_by. These fields are usually generated automatically by the ORM framework.For example:
created_atis only generated duringinsert,updated_atis generated duringinsertorupdate.Proposed Solutions
Although these functions can be implemented through the Entity's Hook (ActiveModelBehavior), it is redundant to write them for each entity, and it doesn't make sense. I hope the framework can have the functionality of global hooks, and at the same time, the framework can also provide several commonly used global hooks (such as AuditableHook). Users can also customize global hooks (for example, implementing automatic auditing for
created_byandupdated_by).I think this will be a powerful feature, providing more hooks will be more convenient.
Another suggestion is that there is a lack of
after_get/after_queryhooks in ActiveModelBehavior. This hook can implement further processing of the queried Model(For example: unified data dictionary translation for some fileds in Model.).Current Workarounds
Hardcoding, repetitive copying
Beta Was this translation helpful? Give feedback.
All reactions