Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/25.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 如何使用like';KD%&x27;在RubyonRails中,ActiveRecord与_Ruby On Rails_Ruby_Activerecord - Fatal编程技术网

Ruby on rails 如何使用like';KD%&x27;在RubyonRails中,ActiveRecord与

Ruby on rails 如何使用like';KD%&x27;在RubyonRails中,ActiveRecord与,ruby-on-rails,ruby,activerecord,Ruby On Rails,Ruby,Activerecord,我在RubyonRailsActiveRecord中有很多关系,我需要像'FD%'这样的查询,找不到任何关于这个的例子 以下是我需要的: class Test < ActiveRecord::Base has_many :client, -> {where(name: like 'FD%')} 类测试{where(名称:like'FD%')} 它一直告诉我,喜欢是不允许的。不知道有没有人知道怎么做 您可以这样做: has_many :client, -> {where

我在RubyonRailsActiveRecord中有很多关系,我需要像'FD%'这样的查询,找不到任何关于这个的例子

以下是我需要的:

class Test < ActiveRecord::Base
   has_many :client, -> {where(name: like 'FD%')}
类测试{where(名称:like'FD%')}
它一直告诉我,喜欢是不允许的。不知道有没有人知道怎么做

您可以这样做:

has_many :client, -> {where("clients.name like 'FD%'")}
客户端。
是可选的,但是如果您的测试模型有name列,您将得到一个错误