Ruby on rails 为什么这个作用域会导致rails应用程序中的重复出现?
Ruby on rails 为什么这个作用域会导致rails应用程序中的重复出现?,ruby-on-rails,activerecord,Ruby On Rails,Activerecord,scope:name,->(name){where“lower(name)LIKE?”,“%#{name.downcase}%”} 我有一个带有名称属性的模型。当我直接查询该属性时,一切正常。当我尝试使用上面的作用域来消除它时,我开始得到堆栈级错误——不知何故,该作用域甚至在客户机上导致递归。where(true)语句。即使我将其从名称更改为编号,也有可能与内置方法发生冲突,但它不起作用。我忽略了什么 相关模型: class Client < ActiveRecord::Base s
scope:name,->(name){where“lower(name)LIKE?”,“%#{name.downcase}%”}
我有一个带有名称
属性的模型。当我直接查询该属性时,一切正常。当我尝试使用上面的作用域来消除它时,我开始得到堆栈级错误——不知何故,该作用域甚至在客户机上导致递归。where(true)
语句。即使我将其从名称
更改为编号
,也有可能与内置方法发生冲突,但它不起作用。我忽略了什么
相关模型:
class Client < ActiveRecord::Base
scope :name, -> (name){ where "lower(name) LIKE ?", "%#{name.downcase}%"}
end
问题是您的作用域名为
name
。name
方法通常返回类名。一些Rails代码使用了name
方法,例如下面的parent\u name
方法:
parent\u name
可以采用类似于Admin::User
的类名并返回Admin
中的核心函数如compute\u table\u name
使用parent\u name
等方法。当一个作用域被命名为name
时,compute\u table\u name
逻辑和current\u scope
逻辑可能会在一个循环中混淆。这会导致堆栈级别太深
错误
您可以通过将范围更改为以下内容来避免这种情况:
scope :by_name, ->(name) { where "lower(name) LIKE ?", "%#{name.downcase}%" }
问题是您的作用域名为
name
。name
方法通常返回类名。一些Rails代码使用了name
方法,例如下面的parent\u name
方法:
parent\u name
可以采用类似于Admin::User
的类名并返回Admin
中的核心函数如compute\u table\u name
使用parent\u name
等方法。当一个作用域被命名为name
时,compute\u table\u name
逻辑和current\u scope
逻辑可能会在一个循环中混淆。这会导致堆栈级别太深
错误
您可以通过将范围更改为以下内容来避免这种情况:
scope :by_name, ->(name) { where "lower(name) LIKE ?", "%#{name.downcase}%" }
问题是您的作用域名为
name
。name
方法通常返回类名。一些Rails代码使用了name
方法,例如下面的parent\u name
方法:
parent\u name
可以采用类似于Admin::User
的类名并返回Admin
中的核心函数如compute\u table\u name
使用parent\u name
等方法。当一个作用域被命名为name
时,compute\u table\u name
逻辑和current\u scope
逻辑可能会在一个循环中混淆。这会导致堆栈级别太深
错误
您可以通过将范围更改为以下内容来避免这种情况:
scope :by_name, ->(name) { where "lower(name) LIKE ?", "%#{name.downcase}%" }
问题是您的作用域名为
name
。name
方法通常返回类名。一些Rails代码使用了name
方法,例如下面的parent\u name
方法:
parent\u name
可以采用类似于Admin::User
的类名并返回Admin
中的核心函数如compute\u table\u name
使用parent\u name
等方法。当一个作用域被命名为name
时,compute\u table\u name
逻辑和current\u scope
逻辑可能会在一个循环中混淆。这会导致堆栈级别太深
错误
您可以通过将范围更改为以下内容来避免这种情况:
scope :by_name, ->(name) { where "lower(name) LIKE ?", "%#{name.downcase}%" }