You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
hi,i am a new of rust and sea-orm, sea-orm is greate,im not.
there a question i was thinking and try to work around serveral days,today i think i need help someone give me some idea on this.
that,how to avoiod dumb code,
i have a entity named goods, and it's have a many to many relation of material,when user query goods with id, it's should respond goods entity all of subitems and material list
// respond struct i think this is dumb code,there many duplicate lines,but i don't konw how to avoid this duplicate structRespondGoods{pubid:i32,pubname:String,publabel:String,publabel_zh:String,pubimg:String,pubsteps:String,pubdescription:Option<String>,pubcreate_time:DateTimeUtc,pubupdate_time:DateTimeUtc,pubmaterials_list:Option<Vec<material::Model>>,// this line is different of goods entity}
when i make a sea orm query and try to instance a RespondGoods there also have duplicate
let result = sea_orm.query(goods_id).one().await;let material_relation_list = sea_orm.query(goods_result.id).all().await;letmut condition = Condition::any();let material_list = for material_id in material_relation_list {
condition.push(add(Column::eq(material_list)))}let material_detail_list = material::entity::find().filter(condition).all().await;// need return RespondGoods to make a http respond with result dataRespondGoods{id: result.id,// this line till update_time,was same with Model of goods entity,but i still need one by one wirte, i think there maybe have a convenient way to make thisname: result.name,label: result.label,label_zh: result.label_zh,img: result.img,r#type: result.r#type,steps: result.steps,description: result.description,create_time: result.create_time,update_time: result.update_time,materials_list: material_detail_list,}
would someone help me to review my code and give some advice,(any other suggest also please)
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
HELP!
hi,i am a new of rust and sea-orm, sea-orm is greate,im not.
there a question i was thinking and try to work around serveral days,today i think i need help someone give me some idea on this.
that,how to avoiod dumb code,
i have a entity named goods, and it's have a many to many relation of material,when user query goods with id, it's should respond goods entity all of subitems and material list
when i make a sea orm query and try to instance a RespondGoods there also have duplicate
would someone help me to review my code and give some advice,(any other suggest also please)
Beta Was this translation helpful? Give feedback.
All reactions