Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/64.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 如何强制在模型级别加载活动记录(Ruby)?_Ruby On Rails_Activerecord_Eager Loading - Fatal编程技术网

Ruby on rails 如何强制在模型级别加载活动记录(Ruby)?

Ruby on rails 如何强制在模型级别加载活动记录(Ruby)?,ruby-on-rails,activerecord,eager-loading,Ruby On Rails,Activerecord,Eager Loading,我们想强制我们的Post模型加载所有评论 现在,我们必须在find(:all)处指定即时加载,如下所示: Post.all(:include => [ :comment ]) class Post < ActiveRecord::Base has_many :comments, :include <all comments> # eager load?? 有没有一种方法可以在后期模型级别强制加载默认值,而不是在每次查找时都这样做?如下所示: Post.all(:

我们想强制我们的Post模型加载所有评论

现在,我们必须在find(:all)处指定即时加载,如下所示:

Post.all(:include => [ :comment ])
class Post < ActiveRecord::Base
  has_many :comments, :include <all comments>  # eager load??
有没有一种方法可以在后期模型级别强制加载默认值,而不是在每次查找时都这样做?如下所示:

Post.all(:include => [ :comment ])
class Post < ActiveRecord::Base
  has_many :comments, :include <all comments>  # eager load??
class Post
看起来你会想要为这件事付出代价