我正在尝试使用 Diesel 从数据库加载关联。我定义了以下模型:
#[derive(Identifiable, Queryable, PartialEq, Debug)]
#[table_name = "contacts"]
pub struct Contact {
pub id: i32,
pub firstname: String,
pub lastname: String,
}
#[derive(Identifiable, Queryable, Associations, PartialEq, Debug)]
#[belongs_to(Contact)]
#[table_name = "emails"]
pub struct Email {
pub id: i32,
pub contact_id: i32,
pub label: String,
pub email: String,
}
Run Code Online (Sandbox Code Playgroud)
现在我尝试使用以下代码获取所有联系人及其关联的电子邮件:
let result = match contacts::table
.inner_join(emails::table)
.load::<models::Contact, Vec<models::Email>>(&self.conn)
{
Ok(rows) => rows,
Err(_) => return Err(io::Error::new(io::ErrorKind::Other, "Database error")),
};
Run Code Online (Sandbox Code Playgroud)
但这是行不通的。该错误与不满足的特征界限有关:
error[E0107]: wrong number of type arguments: expected 1, found …Run Code Online (Sandbox Code Playgroud)