Rails 在复杂的保存中搞砸了 SQL

发布于 2024-08-10 18:28:35 字数 630 浏览 2 评论 0原文

我正在做一些看起来很简单的事情,但是 Rails 搞乱了 SQL。我可以只执行我自己的 SQL,但框架应该能够处理这个问题。

这是我尝试执行的保存:

w = WhipSenVote.find(:first, :conditions => ["whip_bill_id = ? AND whip_sen_id = ?", bill_id, k])
w.votes_no = w.votes_no - 1
w.save

我生成的 SQL 如下所示:

SELECT * 
FROM "whip_sen_votes" 
WHERE (whip_bill_id = E'1' AND whip_sen_id = 7) 
LIMIT 1

然后:

UPDATE "whip_sen_votes" 
SET "votes_yes" = 14, "updated_at" = '2009-11-13 19:55:54.807000' 
WHERE "id" = 15

第一个 select 语句是正确的,但正如您所看到的,尽管 votes_yes 值是正确的,但 Update SQL 语句非常错误。

有什么想法吗?谢谢!

I am doing something seemingly pretty easy, but Rails is messing up the SQL. I could just execute my own SQL, but the framework should be able to handle this.

Here is the save I am trying to perform:

w = WhipSenVote.find(:first, :conditions => ["whip_bill_id = ? AND whip_sen_id = ?", bill_id, k])
w.votes_no = w.votes_no - 1
w.save

My generated SQL looks like this:

SELECT * 
FROM "whip_sen_votes" 
WHERE (whip_bill_id = E'1' AND whip_sen_id = 7) 
LIMIT 1

And then:

UPDATE "whip_sen_votes" 
SET "votes_yes" = 14, "updated_at" = '2009-11-13 19:55:54.807000' 
WHERE "id" = 15

The first select statement is correct, but as you can see, the Update SQL statement is pretty wrong, though the votes_yes value is correct.

Any ideas? Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

脱离于你 2024-08-17 18:28:35

查看 WhipSenVote 模型将会有所帮助。

您还可以使用 递减!

It would help to see the WhipSenVote model.

you can also use decrement!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文