Ruby on rails 正在缓存具有\u多个路径的ActiveRecord对象:
当我试图缓存一个具有has_many-through:关系的ActiveRecord对象时,在重新加载或保存它之前,我无法缓存该对象 person.rb:Ruby on rails 正在缓存具有\u多个路径的ActiveRecord对象:,ruby-on-rails,ruby,caching,marshalling,dalli,Ruby On Rails,Ruby,Caching,Marshalling,Dalli,当我试图缓存一个具有has_many-through:关系的ActiveRecord对象时,在重新加载或保存它之前,我无法缓存该对象 person.rb: class Person < ActiveRecord::Base attr_accessible :name has_many :person_locations has_many :locations, through: :person_locations has_many :person_items has
class Person < ActiveRecord::Base
attr_accessible :name
has_many :person_locations
has_many :locations, through: :person_locations
has_many :person_items
has_many :items, through: :person_items
end
知道为什么缓存这个ActiveRecord对象会失败吗
轨道:3.2.14
达利:2.7
Ruby:1.9.3-p392
编辑
另请参见:原来这是静噪的问题
class PersonItem < ActiveRecord::Base
attr_accessible :item_id, :person_id
belongs_to :item
belongs_to :person
end
class Item < ActiveRecord::Base
attr_accessible :description
has_many :person_items
has_many :people, through: :person_items
end
p = Person.create
p.items << Item.create
Rails.cache.write Time.now, p
=> false
#now if I save or reload p
p.save # or p.reload
Rails.cache.write Time.now, p
=> truthy
p = Person.new
p.items << Item.new
Rails.cache.write Time.now, p