【发布时间】:2009-08-21 18:12:36
【问题描述】:
我的情况是,我将 sqlite 与 ActiveRecord 和 Rails 一起使用(另外,这是 JRuby,所以我实际上正在使用 jdbcsqlite 适配器,以防万一)。现在,我试图在表 attention_seekers 中插入一行,但前提是没有其他现有的类似行。因此,
unless AttentionSeeker.find(:first, :conditions => {:key_id => key.id, :locale_id => l.id})
item = AttentionSeeker.new(:key_id => key.id, :locale_id => l.id)
item.save
end
这是日志中生成的输出:
CACHE (0.0ms) SELECT * FROM attention_seekers WHERE (attention_seekers.key_id = 318 AND attention_seekers.locale_id = 20)
AttentionSeeker Create (1.0ms) INSERT INTO attention_seekers (key_id, locale_id) VALUES(318, 20)
CACHE (0.0ms) SELECT * FROM attention_seekers WHERE (attention_seekers.key_id = 318 AND attention_seekers.locale_id = 20)
AttentionSeeker Create (2.0ms) INSERT INTO attention_seekers (key_id, locale_id) VALUES(318, 20)
如您所见,由于某种原因,该查找被缓存,即使我插入了影响它的元素。我做错了什么/如何阻止这种行为?
【问题讨论】:
标签: ruby-on-rails sqlite activerecord