@@ -8,7 +8,6 @@ module RailsAdmin
88 module Adapters
99 module Mongoid
1010 DISABLED_COLUMN_TYPES = [ 'Range' , 'Moped::BSON::Binary' , 'BSON::Binary' , 'Mongoid::Geospatial::Point' ]
11- ObjectId = defined? ( Moped ::BSON ) ? Moped ::BSON ::ObjectId : BSON ::ObjectId # rubocop:disable ConstantName
1211
1312 def new ( params = { } )
1413 AbstractObject . new ( model . new ( params ) )
@@ -67,9 +66,7 @@ def associations
6766
6867 def properties
6968 fields = model . fields . reject { |_name , field | DISABLED_COLUMN_TYPES . include? ( field . type . to_s ) }
70- fields . collect do |_name , field |
71- Property . new ( field , model )
72- end
69+ fields . collect { |_name , field | Property . new ( field , model ) }
7370 end
7471
7572 def table_name
@@ -102,6 +99,7 @@ def make_field_conditions(field, value, operator)
10299 conditions_per_collection = { }
103100 field . searchable_columns . each do |column_infos |
104101 collection_name , column_name = parse_collection_name ( column_infos [ :column ] )
102+ value = parse_field_value ( field , value )
105103 statement = build_statement ( column_name , column_infos [ :type ] , value , operator )
106104 next unless statement
107105 conditions_per_collection [ collection_name ] ||= [ ]
@@ -114,7 +112,8 @@ def query_conditions(query, fields = config.list.fields.select(&:queryable?))
114112 statements = [ ]
115113
116114 fields . each do |field |
117- conditions_per_collection = make_field_conditions ( field , query , field . search_operator )
115+ value = parse_field_value ( field , query )
116+ conditions_per_collection = make_field_conditions ( field , value , field . search_operator )
118117 statements . concat make_condition_for_current_collection ( field , conditions_per_collection )
119118 end
120119
@@ -134,7 +133,8 @@ def filter_conditions(filters, fields = config.list.fields.select(&:filterable?)
134133 filters_dump . each do |_ , filter_dump |
135134 field = fields . detect { |f | f . name . to_s == field_name }
136135 next unless field
137- conditions_per_collection = make_field_conditions ( field , filter_dump [ :v ] , ( filter_dump [ :o ] || 'default' ) )
136+ value = parse_field_value ( field , filter_dump [ :v ] )
137+ conditions_per_collection = make_field_conditions ( field , value , ( filter_dump [ :o ] || 'default' ) )
138138 field_statements = make_condition_for_current_collection ( field , conditions_per_collection )
139139 if field_statements . many?
140140 statements << { '$or' => field_statements }
@@ -265,8 +265,7 @@ def build_statement_for_enum
265265 end
266266
267267 def build_statement_for_belongs_to_association_or_bson_object_id
268- object_id = ( object_id_from_string ( @value ) rescue nil )
269- { @column => object_id } if object_id
268+ { @column => @value } if @value
270269 end
271270
272271 def range_filter ( min , max )
@@ -278,10 +277,6 @@ def range_filter(min, max)
278277 { @column => { '$lte' => max } }
279278 end
280279 end
281-
282- def object_id_from_string ( str )
283- ObjectId . from_string ( str )
284- end
285280 end
286281 end
287282 end
0 commit comments