我在 Rails 应用程序中有一个数据库,链接如下:人知道它的学校,它知道它的学校规则。
我正在尝试编写一个迁移,在 Person 中创建一个 CanDoThis 列,并使用 School Rules 中的相关 IsThisAllowed 列填充它。这是我到目前为止所拥有的,但它给了我一个“表名“school_rules”指定了不止一次”错误。
UPDATE people
SET people.canRunInHalls = school_rules.RunningInHallsIsAllowed
FROM school_rules
JOIN school_rules on school_rules.school_id = schools.id
JOIN schools ON schools.id = people.school_id;
尝试了一些新的东西 - 得到这个错误:错误:对表“人”的 FROM 子句条目的无效引用
提示:表“people”有一个条目,但不能从这部分查询中引用它。
UPDATE people
SET people.canRunInHalls = school_rules.RunningInHallsIsAllowed
FROM schools s
JOIN school_rules on school_rules.school_id = s.id
JOIN schools ON schools.id = people.school_id;
编辑:尝试绘制架构
people
-------------
id
school_id
canRunInHalls
schools
_______________
id
people
school_rules_id
school_rules
_______________
id
school_id
RunningInHallsIsAllowed