【问题标题】:Changing like query in a rails_admin association在 rails_admin 关联中更改类似查询
【发布时间】:2016-01-31 14:01:09
【问题描述】:

我正在使用 rails admin 并且有两个简单的模型:

class Spot < ActiveRecord::Base
    has_many :user_spots
end

class UserSpot < ActiveRecord::Base
    belongs_to :spot
end

RailsAdmin.config do |config|
    config.model UserSpot do
        exclude_fields :id, :created_at, :updated_at
    end
end

当我在管理区域添加新 Spot 时,它会正确显示下拉列表,

但是当我开始输入时,它默认执行以下sql:

  Spot Load (0.6ms)  SELECT  `spots`.* FROM `spots` WHERE ((LOWER(spots.name) LIKE '%n%') OR (LOWER(spots.about) LIKE '%n%') OR (LOWER(spots.hours) LIKE '%n%') OR (LOWER(spots.location) LIKE '%n%') OR (LOWER(spots.call_info) LIKE '%n%') OR (LOWER(spots.website) LIKE '%n%') OR (LOWER(spots.menu) LIKE '%n%'))  ORDER BY spots.id desc LIMIT 30

我只想搜索姓名。有可能吗?

【问题讨论】:

    标签: sql ruby-on-rails ruby activerecord rails-admin


    【解决方案1】:

    你可以这样配置:

    RailsAdmin.config do |config|
      config.model UserSpot do
        exclude_fields :id, :created_at, :updated_at
        list do
          field :about do
            searchable false
          end
    
          field :hours do
            searchable false
          end
    
          # Like this mark false all the fields you don't want to 
          # search. By default all fields are searchable.
        end
      end
    end
    

    查看this wiki了解更多信息。

    【讨论】:

    • 您好,我想将 LIMIT 30 增加到 50,您能告诉我如何实现吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-08-29
    • 1970-01-01
    • 2014-03-11
    • 2011-10-16
    • 2013-03-05
    • 2021-07-01
    相关资源
    最近更新 更多