Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
通过在 belongs_to 对象上将 FK 设置为 nil 来破坏 has_one 和 belongs_to 的关联是唯一的方法吗?
因为我记得,一旦你设置了级联删除,你只需要删除对象,它就会删除所有依赖项。
希望这会有所帮助,干杯
设置@obj1.obj2 = nil不行吗?
@obj1.obj2 = nil
但这不会删除belongs_to 记录。如果你想这样做,你需要做@obj1.obj2.delete
@obj1.obj2.delete