Tag: 预加载

轨。 在开发模式下预加载类

在开发模式下预加载Rails模型的正确方法是什么? 背景:Rails 2.2,memcahe as cache store。 当Rails首先在生产模式下启动时,它会预加载并缓存所有模型。 在开发模式下,它使用laizy加载。 这就是为什么我们将任何模型存储到rails缓存中,例如,在app的下一个loadind上的Rails.cache.write(“key”,User.find(0)),当我们尝试执行Rails.cache.read(“key” )memcache fire,即User是未知的类/模块。 在这种情况下,预加载课程的正确方法是什么?

预加载与动态条件的关联

我有Place模型和Event模型。 地方可以 在特定日期举办活动。 如何在没有N + 1查询问题的特定日期设置我的关联和查找器来加载所有地方,包括(急切加载)他们的事件? 我尝试过的: class Place has_many :events end Place.all.preload(:events).where(“events.start_date > ‘#{time_in_the_future}'”) #ActiveRecord::StatementInvalid: PG::UndefinedTable: ERROR: missing FROM-clause entry for table “events”. Place.all.includes(:events).where(“events.start_date > ‘#{time_in_the_future}'”).references(:event) # only loads places that have an event at the specific date and not all places including their events (if there are any events). 我成功地想出了一个能够做我想要的但不是动态的关联(不接受参数) class Place has_many […]