datastax_rails 2.0.12 → 2.0.15
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/Rakefile +5 -5
- data/lib/blankslate.rb +8 -11
- data/lib/cql-rb_extensions.rb +5 -3
- data/lib/datastax_rails/associations/association.rb +93 -101
- data/lib/datastax_rails/associations/association_scope.rb +7 -7
- data/lib/datastax_rails/associations/belongs_to_association.rb +46 -48
- data/lib/datastax_rails/associations/builder/association.rb +32 -31
- data/lib/datastax_rails/associations/builder/belongs_to.rb +19 -20
- data/lib/datastax_rails/associations/builder/collection_association.rb +32 -32
- data/lib/datastax_rails/associations/builder/has_and_belongs_to_many.rb +21 -21
- data/lib/datastax_rails/associations/builder/has_many.rb +39 -40
- data/lib/datastax_rails/associations/builder/has_one.rb +30 -31
- data/lib/datastax_rails/associations/builder/singular_association.rb +31 -33
- data/lib/datastax_rails/associations/collection_association.rb +129 -135
- data/lib/datastax_rails/associations/collection_proxy.rb +21 -21
- data/lib/datastax_rails/associations/has_and_belongs_to_many_association.rb +26 -26
- data/lib/datastax_rails/associations/has_many_association.rb +38 -38
- data/lib/datastax_rails/associations/has_one_association.rb +31 -32
- data/lib/datastax_rails/associations/singular_association.rb +31 -30
- data/lib/datastax_rails/associations.rb +27 -24
- data/lib/datastax_rails/attribute_assignment.rb +17 -17
- data/lib/datastax_rails/attribute_methods/definition.rb +4 -4
- data/lib/datastax_rails/attribute_methods/dirty.rb +34 -33
- data/lib/datastax_rails/attribute_methods/primary_key.rb +3 -8
- data/lib/datastax_rails/attribute_methods/read.rb +10 -12
- data/lib/datastax_rails/attribute_methods/typecasting.rb +36 -35
- data/lib/datastax_rails/attribute_methods/write.rb +5 -6
- data/lib/datastax_rails/attribute_methods.rb +52 -56
- data/lib/datastax_rails/base.rb +122 -125
- data/lib/datastax_rails/callbacks.rb +15 -9
- data/lib/datastax_rails/cassandra_only_model.rb +6 -6
- data/lib/datastax_rails/collection.rb +5 -7
- data/lib/datastax_rails/column.rb +130 -118
- data/lib/datastax_rails/connection/statement_cache.rb +3 -3
- data/lib/datastax_rails/connection.rb +42 -33
- data/lib/datastax_rails/cql/alter_column_family.rb +19 -21
- data/lib/datastax_rails/cql/base.rb +8 -11
- data/lib/datastax_rails/cql/column_family.rb +11 -10
- data/lib/datastax_rails/cql/consistency.rb +2 -2
- data/lib/datastax_rails/cql/create_column_family.rb +15 -15
- data/lib/datastax_rails/cql/create_index.rb +5 -5
- data/lib/datastax_rails/cql/create_keyspace.rb +7 -7
- data/lib/datastax_rails/cql/delete.rb +16 -29
- data/lib/datastax_rails/cql/drop_column_family.rb +2 -2
- data/lib/datastax_rails/cql/drop_index.rb +2 -2
- data/lib/datastax_rails/cql/drop_keyspace.rb +2 -2
- data/lib/datastax_rails/cql/insert.rb +10 -16
- data/lib/datastax_rails/cql/select.rb +21 -33
- data/lib/datastax_rails/cql/truncate.rb +2 -2
- data/lib/datastax_rails/cql/update.rb +16 -24
- data/lib/datastax_rails/cql/use_keyspace.rb +2 -2
- data/lib/datastax_rails/cql.rb +2 -2
- data/lib/datastax_rails/dynamic_model.rb +32 -29
- data/lib/datastax_rails/errors.rb +6 -6
- data/lib/datastax_rails/grouped_collection.rb +3 -3
- data/lib/datastax_rails/inheritance.rb +9 -9
- data/lib/datastax_rails/payload_model.rb +24 -20
- data/lib/datastax_rails/persistence.rb +116 -110
- data/lib/datastax_rails/railtie.rb +7 -7
- data/lib/datastax_rails/reflection.rb +61 -59
- data/lib/datastax_rails/relation/batches.rb +12 -13
- data/lib/datastax_rails/relation/facet_methods.rb +44 -33
- data/lib/datastax_rails/relation/finder_methods.rb +95 -91
- data/lib/datastax_rails/relation/modification_methods.rb +5 -5
- data/lib/datastax_rails/relation/search_methods.rb +102 -102
- data/lib/datastax_rails/relation/spawn_methods.rb +25 -24
- data/lib/datastax_rails/relation/stats_methods.rb +9 -8
- data/lib/datastax_rails/relation.rb +165 -170
- data/lib/datastax_rails/rsolr_client_wrapper.rb +3 -3
- data/lib/datastax_rails/schema/cassandra.rb +44 -43
- data/lib/datastax_rails/schema/migrator.rb +52 -52
- data/lib/datastax_rails/schema/solr.rb +55 -47
- data/lib/datastax_rails/schema_cache.rb +1 -3
- data/lib/datastax_rails/scoping/default.rb +2 -3
- data/lib/datastax_rails/scoping/named.rb +3 -5
- data/lib/datastax_rails/scoping.rb +11 -12
- data/lib/datastax_rails/serialization.rb +34 -31
- data/lib/datastax_rails/serializers/xml_serializer.rb +178 -175
- data/lib/datastax_rails/timestamps.rb +4 -4
- data/lib/datastax_rails/types/dirty_collection.rb +57 -57
- data/lib/datastax_rails/types/dynamic_list.rb +1 -1
- data/lib/datastax_rails/types/dynamic_map.rb +5 -7
- data/lib/datastax_rails/types/dynamic_set.rb +2 -2
- data/lib/datastax_rails/util/solr_repair.rb +3 -3
- data/lib/datastax_rails/validations/associated.rb +8 -6
- data/lib/datastax_rails/validations/uniqueness.rb +8 -8
- data/lib/datastax_rails/validations.rb +9 -10
- data/lib/datastax_rails/version.rb +2 -1
- data/lib/datastax_rails/wide_storage_model.rb +6 -6
- data/lib/datastax_rails.rb +13 -9
- data/lib/schema_migration.rb +3 -3
- data/spec/datastax_rails/associations/belongs_to_association_spec.rb +2 -2
- data/spec/datastax_rails/associations/collection_association_spec.rb +14 -14
- data/spec/datastax_rails/associations/has_many_association_spec.rb +20 -20
- data/spec/datastax_rails/associations_spec.rb +11 -11
- data/spec/datastax_rails/attribute_methods_spec.rb +25 -25
- data/spec/datastax_rails/base_spec.rb +24 -24
- data/spec/datastax_rails/callbacks_spec.rb +21 -21
- data/spec/datastax_rails/column_spec.rb +133 -132
- data/spec/datastax_rails/connection/statement_cache_spec.rb +2 -2
- data/spec/datastax_rails/cql/base_spec.rb +4 -4
- data/spec/datastax_rails/cql/delete_spec.rb +19 -0
- data/spec/datastax_rails/cql/select_spec.rb +8 -8
- data/spec/datastax_rails/cql/update_spec.rb +8 -10
- data/spec/datastax_rails/dynamic_model_spec.rb +36 -22
- data/spec/datastax_rails/inheritance_spec.rb +11 -14
- data/spec/datastax_rails/persistence_spec.rb +73 -74
- data/spec/datastax_rails/relation/batches_spec.rb +13 -13
- data/spec/datastax_rails/relation/facet_methods_spec.rb +43 -35
- data/spec/datastax_rails/relation/finder_methods_spec.rb +77 -78
- data/spec/datastax_rails/relation/modification_methods_spec.rb +19 -19
- data/spec/datastax_rails/relation/search_methods_spec.rb +160 -160
- data/spec/datastax_rails/relation/spawn_methods_spec.rb +18 -18
- data/spec/datastax_rails/relation_spec.rb +119 -116
- data/spec/datastax_rails/schema/migrator_spec.rb +30 -30
- data/spec/datastax_rails/schema/solr_spec.rb +15 -15
- data/spec/datastax_rails/scoping/default_spec.rb +9 -9
- data/spec/datastax_rails/types/dynamic_list_spec.rb +12 -12
- data/spec/datastax_rails/types/dynamic_map_spec.rb +10 -10
- data/spec/datastax_rails/types/dynamic_set_spec.rb +22 -10
- data/spec/datastax_rails/validations/uniqueness_spec.rb +25 -25
- data/spec/datastax_rails/wide_storage_model_spec.rb +11 -0
- data/spec/datastax_rails_spec.rb +2 -2
- data/spec/dummy/config/application.rb +2 -3
- data/spec/dummy/config/boot.rb +1 -1
- data/spec/dummy/config/environments/development.rb +3 -3
- data/spec/dummy/config/environments/test.rb +1 -1
- data/spec/dummy/config/initializers/session_store.rb +1 -1
- data/spec/dummy/config/initializers/wrap_parameters.rb +1 -1
- data/spec/factories/audit_logs.rb +6 -0
- data/spec/factories/hobbies.rb +6 -0
- data/spec/factories/people.rb +5 -0
- data/spec/feature/dynamic_fields_spec.rb +4 -4
- data/spec/feature/overloaded_tables_spec.rb +11 -12
- data/spec/spec_helper.rb +17 -14
- data/spec/support/datastax_test_hook.rb +2 -2
- data/spec/support/default_consistency_shared_examples.rb +11 -11
- data/spec/support/models.rb +31 -32
- metadata +40 -6
- data/lib/datastax_rails/attribute_methods/before_type_cast.rb +0 -71
- data/lib/datastax_rails/log_subscriber.rb +0 -0
- data/spec/dummy/ks/migrate/20111117224534_models.rb +0 -20
@@ -20,14 +20,14 @@ module DatastaxRails
|
|
20
20
|
super
|
21
21
|
end
|
22
22
|
|
23
|
-
|
23
|
+
private
|
24
24
|
|
25
25
|
def _create_record(*args)
|
26
|
-
if
|
26
|
+
if record_timestamps
|
27
27
|
current_time = current_time_from_proper_timezone
|
28
28
|
|
29
29
|
all_timestamp_attributes.each do |column|
|
30
|
-
if respond_to?(column) && respond_to?("#{column}=") &&
|
30
|
+
if respond_to?(column) && respond_to?("#{column}=") && send(column).nil?
|
31
31
|
write_attribute(column.to_s, current_time)
|
32
32
|
end
|
33
33
|
end
|
@@ -50,7 +50,7 @@ module DatastaxRails
|
|
50
50
|
end
|
51
51
|
|
52
52
|
def should_record_timestamps?
|
53
|
-
|
53
|
+
record_timestamps && (changed? || (attributes.keys & self.class.serialized_attributes.keys).present?)
|
54
54
|
end
|
55
55
|
|
56
56
|
def timestamp_attributes_for_create_in_model
|
@@ -1,88 +1,88 @@
|
|
1
|
-
# An extension to normal arrays and hashes that allow for tracking of dirty values. This is
|
2
|
-
# used by ActiveModel's change tracking framework.
|
3
1
|
module DatastaxRails
|
4
2
|
module Types
|
3
|
+
# An extension to normal arrays and hashes that allow for tracking of dirty values. This is
|
4
|
+
# used by ActiveModel's change tracking framework.
|
5
5
|
module DirtyCollection
|
6
6
|
extend ActiveSupport::Concern
|
7
|
-
|
7
|
+
mattr_accessor :dsr_ignore_modifications
|
8
|
+
|
8
9
|
included do
|
9
10
|
attr_accessor :record, :name
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
end
|
11
|
+
|
12
|
+
ms = [:<<, :delete, :[]=, :add, :subtract, :store, :push, :pop, :unshift, :shift, :insert, :clear] +
|
13
|
+
ActiveSupport::HashWithIndifferentAccess.instance_methods(true).select { |m| m.to_s.ends_with?('!') } +
|
14
|
+
Array.instance_methods(true).select { |m| m.to_s.ends_with?('!') } +
|
15
|
+
Set.instance_methods(true).select { |m| m.to_s.ends_with?('!') }
|
16
|
+
|
17
|
+
ms.each do |m|
|
18
|
+
next unless instance_methods.include?(m)
|
19
|
+
alias_method "___#{m}", m
|
20
|
+
original_method = instance_method(m)
|
21
|
+
define_method(m) do |*args, &block|
|
22
|
+
modifying do
|
23
|
+
original_method.bind(self).call(*args, &block)
|
24
24
|
end
|
25
25
|
end
|
26
26
|
end
|
27
27
|
end
|
28
|
-
|
28
|
+
|
29
29
|
def initialize(record, name, collection)
|
30
30
|
@record = record
|
31
31
|
@name = name.to_s
|
32
|
-
|
32
|
+
|
33
33
|
super(collection)
|
34
34
|
organize_collection
|
35
35
|
end
|
36
|
-
|
36
|
+
|
37
37
|
def delete(obj)
|
38
38
|
modifying do
|
39
39
|
super
|
40
40
|
end
|
41
41
|
end
|
42
|
-
|
42
|
+
|
43
|
+
# FIXME: How do we make this thread-safe?
|
43
44
|
def self.ignore_modifications
|
44
|
-
original =
|
45
|
-
|
45
|
+
original = dsr_ignore_modifications
|
46
|
+
self.dsr_ignore_modifications = true
|
46
47
|
result = yield
|
47
|
-
|
48
|
+
self.dsr_ignore_modifications = original
|
48
49
|
result
|
49
50
|
end
|
50
|
-
|
51
|
+
|
51
52
|
private
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
record.changed_attributes[name] = original
|
72
|
-
end
|
73
|
-
|
74
|
-
record.attributes[name] = self
|
75
|
-
|
76
|
-
result
|
53
|
+
|
54
|
+
def modifying
|
55
|
+
# So there's a problem with overriding the map! method on Array.
|
56
|
+
# When we do the update to record.attributes, HashWithIndifferentAccess
|
57
|
+
# calls .map! on our Array. This causes infinite recursion which
|
58
|
+
# I find is generally not a desired behavior. We use a variable
|
59
|
+
# to tell if we've already hijacked the call.
|
60
|
+
if dsr_ignore_modifications
|
61
|
+
yield
|
62
|
+
else
|
63
|
+
DirtyCollection.ignore_modifications do
|
64
|
+
original = dup unless record.changed_attributes.key?(name)
|
65
|
+
|
66
|
+
result = yield
|
67
|
+
|
68
|
+
organize_collection
|
69
|
+
|
70
|
+
if !record.changed_attributes.key?(name) && original != self
|
71
|
+
record.changed_attributes[name] = original
|
77
72
|
end
|
73
|
+
|
74
|
+
record.attributes[name] = self
|
75
|
+
|
76
|
+
result
|
78
77
|
end
|
79
78
|
end
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
79
|
+
end
|
80
|
+
|
81
|
+
# A hook to allow implementing classes to muck with the collection
|
82
|
+
# before we check it for equality.
|
83
|
+
def organize_collection
|
84
|
+
# No-op
|
85
|
+
end
|
86
86
|
end
|
87
87
|
end
|
88
|
-
end
|
88
|
+
end
|
@@ -9,23 +9,21 @@ module DatastaxRails
|
|
9
9
|
# between them and dynamic fields.
|
10
10
|
class DynamicMap < ActiveSupport::HashWithIndifferentAccess
|
11
11
|
include DirtyCollection
|
12
|
-
|
12
|
+
|
13
13
|
def dup
|
14
14
|
self.class.new(record, name, self).tap do |new_hash|
|
15
15
|
new_hash.default = default
|
16
16
|
end
|
17
17
|
end
|
18
|
-
|
18
|
+
|
19
19
|
def [](key)
|
20
20
|
super(convert_key(key))
|
21
21
|
end
|
22
|
-
|
22
|
+
|
23
23
|
def convert_key(key)
|
24
|
-
unless key.to_s.starts_with?(name)
|
25
|
-
key = name + key.to_s
|
26
|
-
end
|
24
|
+
key = name + key.to_s unless key.to_s.starts_with?(name)
|
27
25
|
super(key)
|
28
26
|
end
|
29
27
|
end
|
30
28
|
end
|
31
|
-
end
|
29
|
+
end
|
@@ -1,10 +1,10 @@
|
|
1
1
|
module DatastaxRails
|
2
2
|
module Types
|
3
3
|
# A collection type that allows you to store an un-ordered, unique
|
4
|
-
# set of entries. Changes are tracked by hooking into ActiveModel's
|
4
|
+
# set of entries. Changes are tracked by hooking into ActiveModel's
|
5
5
|
# built-in change tracking.
|
6
6
|
class DynamicSet < Set
|
7
7
|
include DirtyCollection
|
8
8
|
end
|
9
9
|
end
|
10
|
-
end
|
10
|
+
end
|
@@ -2,12 +2,12 @@ module DatastaxRails
|
|
2
2
|
module SolrRepair
|
3
3
|
def repair_solr
|
4
4
|
encoded = {}
|
5
|
-
|
6
|
-
value =
|
5
|
+
attributes.keys.each do |column_name|
|
6
|
+
value = read_attribute(column_name)
|
7
7
|
encoded[column_name.to_s] = self.class.column_for_attribute(column_name).type_cast_for_solr(value)
|
8
8
|
end
|
9
9
|
xml_doc = RSolr::Xml::Generator.new.add(encoded)
|
10
|
-
self.class.solr_connection.update(:
|
10
|
+
self.class.solr_connection.update(data: xml_doc, params: { replacefields: false })
|
11
11
|
end
|
12
12
|
end
|
13
13
|
end
|
@@ -2,8 +2,8 @@ module DatastaxRails
|
|
2
2
|
module Validations
|
3
3
|
class AssociatedValidator < ActiveModel::EachValidator
|
4
4
|
def validate_each(record, attribute, value)
|
5
|
-
if Array.wrap(value).reject {|r| r.destroyed? || r.valid?}.any?
|
6
|
-
record.errors.add(attribute, :invalid, options.merge(:
|
5
|
+
if Array.wrap(value).reject { |r| r.destroyed? || r.valid? }.any?
|
6
|
+
record.errors.add(attribute, :invalid, options.merge(value: value))
|
7
7
|
end
|
8
8
|
end
|
9
9
|
end
|
@@ -18,7 +18,8 @@ module DatastaxRails
|
|
18
18
|
# validates_associated :pages, :library
|
19
19
|
# end
|
20
20
|
#
|
21
|
-
# WARNING: This validation must not be used on both ends of an association.
|
21
|
+
# WARNING: This validation must not be used on both ends of an association.
|
22
|
+
# Doing so will lead to a circular dependency and cause infinite recursion.
|
22
23
|
#
|
23
24
|
# NOTE: This validation will not fail if the association hasn't been assigned. If you want to
|
24
25
|
# ensure that the association is both present and guaranteed to be valid, you also need to
|
@@ -30,10 +31,11 @@ module DatastaxRails
|
|
30
31
|
# validation contexts by default (+nil+), other options are <tt>:create</tt>
|
31
32
|
# and <tt>:update</tt>.
|
32
33
|
# * <tt>:if</tt> - Specifies a method, proc or string to call to determine if the validation should
|
33
|
-
# occur (e.g. <tt>:if => :allow_validation</tt>, or <tt>:if => Proc.new { |user| user.signup_step > 2 }</tt>).
|
34
|
-
# method, proc or string should return or evaluate to a true or false value.
|
34
|
+
# occur (e.g. <tt>:if => :allow_validation</tt>, or <tt>:if => Proc.new { |user| user.signup_step > 2 }</tt>).
|
35
|
+
# The method, proc or string should return or evaluate to a true or false value.
|
35
36
|
# * <tt>:unless</tt> - Specifies a method, proc or string to call to determine if the validation should
|
36
|
-
# not occur (e.g. <tt>:unless => :skip_validation</tt>, or
|
37
|
+
# not occur (e.g. <tt>:unless => :skip_validation</tt>, or
|
38
|
+
# <tt>:unless => Proc.new { |user| user.signup_step <= 2 }</tt>). The
|
37
39
|
# method, proc or string should return or evaluate to a true or false value.
|
38
40
|
def validates_associated(*attr_names)
|
39
41
|
validates_with AssociatedValidator, _merge_attributes(attr_names)
|
@@ -6,29 +6,29 @@ module DatastaxRails
|
|
6
6
|
def initialize(options)
|
7
7
|
super
|
8
8
|
end
|
9
|
-
|
9
|
+
|
10
10
|
def validate_each(record, attribute, value)
|
11
11
|
return true if options[:allow_blank] && value.blank?
|
12
12
|
# XXX: The following will break if/when abstract base classes
|
13
13
|
# are implemented in datastax_rails (such as STI)
|
14
14
|
finder_class = record.class
|
15
|
-
|
15
|
+
|
16
16
|
scope = finder_class.where(attribute => value)
|
17
|
-
scope = scope.where_not(:
|
18
|
-
|
17
|
+
scope = scope.where_not(id: record.id) if record.persisted?
|
18
|
+
|
19
19
|
Array.wrap(options[:scope]).each do |scope_item|
|
20
20
|
scope_value = record.send(scope_item)
|
21
21
|
scope_value = nil if scope_value.blank?
|
22
22
|
scope = scope.where(scope_item => scope_value)
|
23
23
|
end
|
24
24
|
|
25
|
-
if scope.exists?
|
25
|
+
if scope.exists? # rubocop:disable Style/GuardClause
|
26
26
|
message = options[:message] || 'has already been taken'
|
27
|
-
record.errors.add(attribute, message, options.except(:case_sensitive, :scope).merge(:
|
27
|
+
record.errors.add(attribute, message, options.except(:case_sensitive, :scope).merge(value: value))
|
28
28
|
end
|
29
29
|
end
|
30
30
|
end
|
31
|
-
|
31
|
+
|
32
32
|
module ClassMethods
|
33
33
|
# Validates whether the value of the specified attributes are unique across the system.
|
34
34
|
# Useful for making sure that only one user can be named "davidhh".
|
@@ -112,4 +112,4 @@ module DatastaxRails
|
|
112
112
|
end
|
113
113
|
end
|
114
114
|
end
|
115
|
-
end
|
115
|
+
end
|
@@ -6,11 +6,10 @@ module DatastaxRails
|
|
6
6
|
super("Invalid record: #{@record.errors.full_messages.to_sentence}")
|
7
7
|
end
|
8
8
|
end
|
9
|
-
|
9
|
+
|
10
10
|
module Validations
|
11
11
|
extend ActiveSupport::Concern
|
12
|
-
|
13
|
-
|
12
|
+
|
14
13
|
module ClassMethods
|
15
14
|
def create!(attributes = {})
|
16
15
|
new(attributes).tap do |object|
|
@@ -20,7 +19,6 @@ module DatastaxRails
|
|
20
19
|
end
|
21
20
|
end
|
22
21
|
|
23
|
-
|
24
22
|
# Runs all the validations within the specified context. Returns true if no errors are found,
|
25
23
|
# false otherwise.
|
26
24
|
#
|
@@ -35,18 +33,19 @@ module DatastaxRails
|
|
35
33
|
errors.empty? && output
|
36
34
|
end
|
37
35
|
|
38
|
-
def save(options={})
|
36
|
+
def save(options = {})
|
39
37
|
perform_validations(options) ? super : false
|
40
38
|
end
|
41
|
-
|
39
|
+
|
42
40
|
def save!
|
43
|
-
save ||
|
41
|
+
save || fail(RecordInvalid.new(self))
|
44
42
|
end
|
45
43
|
|
46
44
|
protected
|
47
|
-
|
48
|
-
|
49
|
-
|
45
|
+
|
46
|
+
def perform_validations(options = {})
|
47
|
+
options[:validate] == false || valid?(options[:context])
|
48
|
+
end
|
50
49
|
end
|
51
50
|
end
|
52
51
|
|
@@ -1,13 +1,13 @@
|
|
1
1
|
module DatastaxRails
|
2
2
|
# A special model that is designed to efficiently store very wide data.
|
3
3
|
# This model type assumes that you have a unique ID that you want to
|
4
|
-
# store a lot of data about. The data is stored as a single, very
|
4
|
+
# store a lot of data about. The data is stored as a single, very
|
5
5
|
# wide row; however you can safely treat it as if there were multiple rows.
|
6
6
|
# A common example of this is a logs table
|
7
7
|
#
|
8
8
|
# You can also apply secondary indexes onto the other columns.
|
9
9
|
#
|
10
|
-
# CAVEATS:
|
10
|
+
# CAVEATS:
|
11
11
|
# * Once the cluster attribute is set, it cannot be changed as it becomes the column header in Cassandra
|
12
12
|
#
|
13
13
|
# class AuditLog < DatastaxRails::WideStorageModel
|
@@ -15,7 +15,7 @@ module DatastaxRails
|
|
15
15
|
# self.primary_key = :uuid
|
16
16
|
# self.cluster_by = :created_at
|
17
17
|
# # If you don't want the default ascending sort order
|
18
|
-
# self.create_options = 'CLUSTERING ORDER BY (created_at DESC)'
|
18
|
+
# self.create_options = 'CLUSTERING ORDER BY (created_at DESC)'
|
19
19
|
#
|
20
20
|
# string :uuid
|
21
21
|
# string :message
|
@@ -24,10 +24,10 @@ module DatastaxRails
|
|
24
24
|
# end
|
25
25
|
class WideStorageModel < DatastaxRails::Base
|
26
26
|
self.abstract_class = true
|
27
|
-
|
27
|
+
|
28
28
|
# Returns a primary key hash for updates that includes the cluster key
|
29
29
|
def id_for_update
|
30
|
-
{self.class.primary_key.to_s =>
|
30
|
+
{ self.class.primary_key.to_s => id, self.class.cluster_by.to_s => read_attribute(self.class.cluster_by.to_s) }
|
31
31
|
end
|
32
32
|
end
|
33
|
-
end
|
33
|
+
end
|
data/lib/datastax_rails.rb
CHANGED
@@ -5,7 +5,7 @@ require 'schema_migration'
|
|
5
5
|
# Welcome to DatastaxRails. DatastaxRails::Base is probably a good place to start.
|
6
6
|
module DatastaxRails
|
7
7
|
extend ActiveSupport::Autoload
|
8
|
-
|
8
|
+
|
9
9
|
autoload :Associations
|
10
10
|
autoload :AttributeAssignment
|
11
11
|
autoload :AttributeMethods
|
@@ -16,11 +16,11 @@ module DatastaxRails
|
|
16
16
|
autoload :Column
|
17
17
|
autoload :Collection
|
18
18
|
autoload :Connection
|
19
|
-
|
19
|
+
|
20
20
|
autoload_under 'connection' do
|
21
21
|
autoload :StatementCache
|
22
22
|
end
|
23
|
-
|
23
|
+
|
24
24
|
autoload :Cql
|
25
25
|
autoload :DynamicModel
|
26
26
|
autoload :GroupedCollection
|
@@ -30,7 +30,7 @@ module DatastaxRails
|
|
30
30
|
autoload :Persistence
|
31
31
|
autoload :Reflection
|
32
32
|
autoload :Relation
|
33
|
-
|
33
|
+
|
34
34
|
autoload_under 'relation' do
|
35
35
|
autoload :FinderMethods
|
36
36
|
autoload :ModificationMethods
|
@@ -40,7 +40,7 @@ module DatastaxRails
|
|
40
40
|
autoload :Batches
|
41
41
|
autoload :FacetMethods
|
42
42
|
end
|
43
|
-
|
43
|
+
|
44
44
|
autoload :RSolrClientWrapper, 'datastax_rails/rsolr_client_wrapper'
|
45
45
|
autoload :Schema
|
46
46
|
autoload :Scoping
|
@@ -52,7 +52,8 @@ module DatastaxRails
|
|
52
52
|
autoload :Validations
|
53
53
|
autoload :Version
|
54
54
|
autoload :WideStorageModel
|
55
|
-
|
55
|
+
|
56
|
+
# Module to hold attribute method related functionality
|
56
57
|
module AttributeMethods
|
57
58
|
extend ActiveSupport::Autoload
|
58
59
|
|
@@ -64,7 +65,8 @@ module DatastaxRails
|
|
64
65
|
autoload :Write
|
65
66
|
end
|
66
67
|
end
|
67
|
-
|
68
|
+
|
69
|
+
# Module to hold scoping related functionality
|
68
70
|
module Scoping
|
69
71
|
extend ActiveSupport::Autoload
|
70
72
|
|
@@ -74,15 +76,17 @@ module DatastaxRails
|
|
74
76
|
end
|
75
77
|
end
|
76
78
|
|
79
|
+
# Module to hold Rake task related functionality
|
77
80
|
module Tasks
|
78
81
|
extend ActiveSupport::Autoload
|
79
82
|
autoload :Keyspace
|
80
83
|
autoload :ColumnFamily
|
81
84
|
end
|
82
|
-
|
85
|
+
|
86
|
+
# Module to hold type related functionality
|
83
87
|
module Types
|
84
88
|
extend ActiveSupport::Autoload
|
85
|
-
|
89
|
+
|
86
90
|
eager_autoload do
|
87
91
|
autoload :DirtyCollection
|
88
92
|
autoload :DynamicList
|