Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/user-interface/2.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 “includes”和“group”查询中的德米特定律_Ruby On Rails - Fatal编程技术网

Ruby on rails “includes”和“group”查询中的德米特定律

Ruby on rails “includes”和“group”查询中的德米特定律,ruby-on-rails,Ruby On Rails,我如何在该代码上应用得墨忒尔法 我知道如何通过创建单独的方法、范围。。。。但我不知道如何处理这样的查询 pages = Seo::Page.active .path_with(category) .includes(seo_area: :suburb) .group('suburbs.state') scope:path_with,->category{where('path-like?',“/#{category}/%”}您可以创建类方法或新的作用域来封装Seo:

我如何在该代码上应用得墨忒尔法

我知道如何通过创建单独的方法、范围。。。。但我不知道如何处理这样的查询

  pages = Seo::Page.active
    .path_with(category)
    .includes(seo_area: :suburb)
    .group('suburbs.state')

scope:path_with,->category{where('path-like?',“/#{category}/%”}
您可以创建类方法或新的作用域来封装
Seo::Page
类中的逻辑

def self.grouped(category)
  active
    .path_with(category)
    .includes(seo_area: :suburb)
    .group('suburbs.state')
end

pages = Seo::Page.grouped(category)

您可以创建类方法或新作用域来封装
Seo::Page
类中的逻辑

def self.grouped(category)
  active
    .path_with(category)
    .includes(seo_area: :suburb)
    .group('suburbs.state')
end

pages = Seo::Page.grouped(category)