File tree Expand file tree Collapse file tree 2 files changed +21
-15
lines changed Expand file tree Collapse file tree 2 files changed +21
-15
lines changed Original file line number Diff line number Diff line change @@ -54,15 +54,9 @@ def where(args)
5454 Dynamoid . logger . warn ( detector . warning_message )
5555 end
5656
57- nonexistent_fields = NonexistentFieldsDetector . new ( args , @source ) . fields
58- if nonexistent_fields . present?
59- fields_list = nonexistent_fields . map { |s | "`#{ s } `" } . join ( ', ' )
60- fields_count = nonexistent_fields . size
61-
62- Dynamoid . logger . warn (
63- "where conditions contain nonexistent" \
64- " field #{ 'name' . pluralize ( fields_count ) } #{ fields_list } "
65- )
57+ detector = NonexistentFieldsDetector . new ( args , @source )
58+ if detector . found?
59+ Dynamoid . logger . warn ( detector . warning_message )
6660 end
6761
6862 query . update ( args . symbolize_keys )
Original file line number Diff line number Diff line change @@ -6,19 +6,31 @@ class NonexistentFieldsDetector
66 def initialize ( conditions , source )
77 @conditions = conditions
88 @source = source
9+ @nonexistent_fields = nonexistent_fields
910 end
1011
11- def fields
12- fields_from_conditions - fields_existent
12+ def found?
13+ @nonexistent_fields . present?
14+ end
15+
16+ def warning_message
17+ return unless found?
18+
19+ fields_list = @nonexistent_fields . map { |s | "`#{ s } `" } . join ( ', ' )
20+ count = @nonexistent_fields . size
21+
22+ "where conditions contain nonexistent" \
23+ " field #{ 'name' . pluralize ( count ) } #{ fields_list } "
1324 end
1425
1526 private
1627
28+ def nonexistent_fields
29+ fields_from_conditions - fields_existent
30+ end
31+
1732 def fields_from_conditions
18- @conditions . keys . map do |s |
19- name , _ = s . to_s . split ( '.' )
20- name
21- end . map ( &:to_sym )
33+ @conditions . keys . map { |s | s . to_s . split ( '.' ) [ 0 ] . to_sym }
2234 end
2335
2436 def fields_existent
You can’t perform that action at this time.
0 commit comments