Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Changing like query in a rails_admin association

I am using rails admin and have two simple models:

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

when I am adding a new Spot in the admin area, it shows the dropdown list correctly,

My field

but when I start typing, it executes the following sql by default:

  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

I would like to search only for name. Is it possible?

like image 454
Vitor Oliveira Avatar asked Nov 25 '25 08:11

Vitor Oliveira


1 Answers

You can configure the same as:

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

Check this wiki for more information.

like image 166
Arup Rakshit Avatar answered Nov 26 '25 23:11

Arup Rakshit



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!