gpt4 book ai didi

mysql - delete_all 是否会忽略基于连接表的条件?

转载 作者:行者123 更新时间:2023-11-29 09:56:31 25 4
gpt4 key购买 nike

我观察到 ActiveRecord delete_all 忽略了连接表条件。这是 Rails 社区的已知问题吗?

查询:

DesignPartCategory.joins(:category).where(category: {site_id: INDIA}, designpart_uuid: ['123C']).delete_all

预期结果:

designpart_category 中删除 designpart_category.designpart_uuid IN ('123C') AND designpart_category. Category_id IN(印度);

实际结果:

 DELETE FROM `designpart_category` WHERE `designpart_category`.`designpart_uuid` IN (SELECT designpart_uuid FROM (SELECT `designpart_category`.`designpart_uuid` FROM `designpart_category` INNER JOIN `category` ON `category`.`category_id` = `designpart_category`.`category_id` WHERE (category.site_id =INDIA AND designpart_category.designpart_uuid in ('123C'))) __active_record_temp);

当前delete_all操作只是忽略/丢弃连接表条件并执行查询的其余部分。

我假设情况不应该如此,它应该抛出异常而不是忽略连接。请让我们知道您对此的想法/评论。

最佳答案

您的语法似乎有一些拼写错误,请检查一下 -

DesignPartCategory.joins(:category).where("categories.site_id = ? AND categories.designpart_uuid IN (?)", 'INDIA', ['123C']).delete_all

或者你可以尝试这个:-

DesignPartCategory.joins(:category).where(categories: {site_id: 'INDIA', designpart_uuid: (['123C'])}).delete_all

注:-Delete vs Destroy

关于mysql - delete_all 是否会忽略基于连接表的条件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53755602/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com