【发布时间】:2020-10-27 21:18:59
【问题描述】:
假设我有三个表,a、b 和 c:
create table c (
id serial primary key,
can_edit_b boolean not null
);
create table b (
id serial primary key,
value text not null
);
create table a (
id serial primary key,
c_id integer not null references c(id),
b_id integer not null references b(id)
);
我想更新b(给定c 实例的ID)只要c 的实例被a 的实例引用,该实例也引用b 和c.can_edit_b是真的。我想做的SQL:
update b
set value = "some value"
from c, a
where a.b_id == b.id
where a.c_id == <user id (inserted as a Rust i32)>
where c.can_edit_b == true
我找不到对应于 SQL from 的 relevant method/function in Diesel's API。如果我尝试使用inner_join,那么编译器会告诉我inner_join 没有为UpdateStatement 定义。
【问题讨论】:
-
很难回答您的问题,因为它不包含minimal reproducible example。我们无法分辨代码中存在哪些 crate(及其版本)、类型、特征、字段等。如果您尝试在全新的 Cargo 项目中重现您的设置和错误,我们会更轻松地为您提供帮助,然后 edit 您的问题将包含其他信息。您可以使用Rust-specific 和Diesel-specific MRE 提示来减少您在此处发布的原始代码。谢谢!
标签: sql rust rust-diesel