柴油(防锈库)不允许我发表更新声明

时间:2019-09-01 15:23:14

标签: postgresql rust

结构是

#[derive(Identifiable, Queryable, Debug)]
#[table_name = "users"]
pub struct QueryableUser {
    pub id: i32,
    pub username: String,
    pub password: String,
    pub sex: bool,
    pub profile: Option<String>,
    pub birth: chrono::NaiveDate,
}

当我尝试更新结构时

diesel::update(&queryable_user).set(...);

它给了我这个错误

error[E0277]: the trait bound `user::QueryableUser: diesel::Identifiable` is not satisfied
  --> src\message_handler\set_profile.rs:36:13
   |
36 |             diesel::update(user).set(profile.eq(None));
   |             ^^^^^^^^^^^^^^ the trait `diesel::Identifiable` is not implemented for `user::QueryableUser`
   |
   = help: the following implementations were found:
             <&'ident user::QueryableUser as diesel::Identifiable>
   = note: required because of the requirements on the impl of `diesel::query_builder::IntoUpdateTarget` for `user::QueryableUser`
   = note: required by `diesel::update`

这真的很令人困惑,因为我在我的结构中派生了Identifiable

1 个答案:

答案 0 :(得分:0)

我忘了在export const updateCardMutation = { async updateCard(_, { id, patch }): Promise<Card> { const repository = getRepository(Card); const card = await repository.findOne({ id }); const result = await repository.update(id, { ...patch }); // Added here return { ...card, ...patch, }; }, }; 借用用户