greatest_updated_at 0.1.0 → 0.1.1
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.
- checksums.yaml +4 -4
- data/lib/greatest_updated_at/calculations.rb +4 -3
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2e95b453dd9f4ea33869194dedcd7b9093184b19
|
4
|
+
data.tar.gz: 1d9dab18849262848089db47022fe4df0da795df
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b7ba0a6352aaa2f20d5f0d179f521cadd1f1be87f426c3f13ab7932278dc7f1fd8b9fae887725b30f097fe6180fdb07eb0dc428cd44e72b20504ab4c64742a20
|
7
|
+
data.tar.gz: 1a8ba25c36139c98a5e0970300daeba27da9ea9a34e17eaa806b617e1cc6c9a12360be0a03c249b27aeab8dcf51603694365d7ad3a995201c5f866f3df879e03
|
@@ -33,15 +33,16 @@ module GreatestUpdatedAt
|
|
33
33
|
arel.projections = []
|
34
34
|
|
35
35
|
arel.project greatest_select_val(table_names)
|
36
|
-
|
37
|
-
relation.klass.connection.select_value(arel, 'SQL', arel.bind_values + relation.bind_values)
|
38
36
|
|
37
|
+
# Get the result, and make sure it is cast the same as updated_at
|
38
|
+
result = relation.klass.connection.select_value(arel, 'SQL', arel.bind_values + relation.bind_values)
|
39
|
+
relation.klass.column_types["updated_at"].type_cast_from_database(result)
|
39
40
|
end
|
40
41
|
|
41
42
|
protected
|
42
43
|
def greatest_select_val(table_names)
|
43
44
|
max_calcs = Array(table_names).collect{|name|
|
44
|
-
"MAX(#{connection.quote_table_name(name.to_s)}.#{connection.quote_column_name("updated_at")})"
|
45
|
+
"COALESCE(MAX(#{connection.quote_table_name(name.to_s)}.#{connection.quote_column_name("updated_at")}), 0)"
|
45
46
|
}
|
46
47
|
|
47
48
|
if max_calcs.length == 1
|