假设我有三张table, 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
)只要 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
我在diesel的api中找不到对应于sql的相关方法/函数 from
. 如果我尝试使用 inner_join
然后编译器告诉我 inner_join
未定义 UpdateStatement
.
1条答案
按热度按时间neekobn81#
可以联接表,应用筛选器,然后将其用作更新条件:
这将生成与您的不同的sql,但结果应该相同:
另请参见:
如何在diesel中对postgres数据库执行delete with sub查询?