carnival 0.2.4 → 0.2.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -433,62 +433,6 @@ module Carnival
|
|
433
433
|
end
|
434
434
|
end
|
435
435
|
|
436
|
-
<<<<<<< HEAD
|
437
|
-
def parse_advanced_search_field search_field, field_param, records
|
438
|
-
return records if not field_param["value"].present?
|
439
|
-
return records if field_param["value"] == ""
|
440
|
-
|
441
|
-
if relation_field?(search_field.to_sym)
|
442
|
-
related_model = model_class.reflect_on_association(search_field.to_sym).klass.name.underscore
|
443
|
-
foreign_key = model_class.reflect_on_association(search_field.to_sym).foreign_key
|
444
|
-
if model_class.reflect_on_association(search_field.to_sym).macro == :belongs_to
|
445
|
-
records = records.joins(related_model.split("/").last.to_sym)
|
446
|
-
else
|
447
|
-
records = records.joins(related_model.split("/").last.pluralize)
|
448
|
-
end
|
449
|
-
table = related_model.split("/").last.pluralize
|
450
|
-
column = "id"
|
451
|
-
else
|
452
|
-
table = table_name
|
453
|
-
column = search_field
|
454
|
-
end
|
455
|
-
full_column_query = "#{table}.#{column}"
|
456
|
-
where_clause = nil
|
457
|
-
|
458
|
-
case field_param["operator"]
|
459
|
-
when "equal"
|
460
|
-
if field_param["value"] == "nil"
|
461
|
-
where_clause = "#{full_column_query} is null"
|
462
|
-
else
|
463
|
-
where_clause = "#{full_column_query} = '#{advanced_search_field_value_for_query(field_param["value"])}'"
|
464
|
-
end
|
465
|
-
when "like"
|
466
|
-
where_clause = "#{full_column_query} like '%#{field_param["value"]}%'"
|
467
|
-
when "greater_than"
|
468
|
-
where_clause = "#{full_column_query} >= '#{field_param["value"]}'"
|
469
|
-
when "less_than"
|
470
|
-
where_clause = "#{full_column_query} <= '#{field_param["value"]}'"
|
471
|
-
when "between"
|
472
|
-
where_clause = "#{full_column_query} between '#{field_param["value"]}' and '#{field_param["value2"]}'"
|
473
|
-
else
|
474
|
-
where_clause = "#{full_column_query} = #{advanced_search_field_value_for_query(field_param["value"])}"
|
475
|
-
end
|
476
|
-
records = records.where(where_clause) if where_clause.present?
|
477
|
-
records
|
478
|
-
end
|
479
|
-
|
480
|
-
def advanced_search_field_value_for_query(value)
|
481
|
-
if "true" == value.downcase
|
482
|
-
return "'t'"
|
483
|
-
elsif "false" == value.downcase
|
484
|
-
return "'f'"
|
485
|
-
else
|
486
|
-
"#{value}"
|
487
|
-
end
|
488
|
-
end
|
489
|
-
=======
|
490
|
-
>>>>>>> master
|
491
|
-
|
492
436
|
def is_namespaced?
|
493
437
|
self.class.to_s.split("::").size > 0
|
494
438
|
end
|
data/lib/carnival/version.rb
CHANGED