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)