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
@@ -34,32 +34,32 @@ module DatastaxRails
|
|
34
34
|
# is computed directly through Solr and does not trigger by itself the
|
35
35
|
# instantiation of the actual post records.
|
36
36
|
class CollectionProxy #:nodoc:
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
37
|
+
attr_reader :association
|
38
|
+
alias_method :proxy_association, :association
|
39
|
+
alias_method :proxy_extend, :extend
|
40
|
+
|
41
|
+
instance_methods.each do |m|
|
42
|
+
undef_method m unless m.to_s =~ /^(?:nil\?|send|object_id|to_a)$|^__|^respond_to|proxy_/
|
43
|
+
end
|
44
|
+
|
45
|
+
delegate :order, :limit, :where, to: :scoped
|
46
|
+
delegate :target, :load_target, :loaded?, :scoped, to: :@association
|
43
47
|
delegate :select, :find, :first, :last, :build, :create, :create!, :destroy_all, :destroy,
|
44
|
-
:delete, :delete_all, :count, :size, :length, :empty?, :any?, :many?, :
|
45
|
-
|
48
|
+
:delete, :delete_all, :count, :size, :length, :empty?, :any?, :many?, to: :@association
|
49
|
+
|
46
50
|
def initialize(association)
|
47
51
|
@association = association
|
48
52
|
Array.wrap(association.options[:extend]).each { |ext| proxy_extend(ext) }
|
49
53
|
end
|
50
|
-
|
54
|
+
|
51
55
|
alias_method :new, :build
|
52
|
-
|
53
|
-
def proxy_association
|
54
|
-
@association
|
55
|
-
end
|
56
|
-
|
56
|
+
|
57
57
|
def respond_to?(name, include_private = false)
|
58
58
|
super ||
|
59
59
|
(load_target && target.respond_to?(name, include_private)) ||
|
60
60
|
proxy_association.klass.respond_to?(name, include_private)
|
61
61
|
end
|
62
|
-
|
62
|
+
|
63
63
|
def method_missing(method, *args, &block)
|
64
64
|
if target.respond_to?(method) || (!proxy_association.klass.respond_to?(method) && Class.respond_to?(method))
|
65
65
|
if load_target
|
@@ -78,28 +78,28 @@ module DatastaxRails
|
|
78
78
|
scoped.send(method, *args, &block)
|
79
79
|
end
|
80
80
|
end
|
81
|
-
|
81
|
+
|
82
82
|
# Forwards <tt>===</tt> explicitly to the \target because the instance method
|
83
83
|
# removal above doesn't catch it. Loads the \target if needed.
|
84
84
|
def ===(other)
|
85
|
-
other === load_target
|
85
|
+
other === load_target # rubocop:disable Style/CaseEquality
|
86
86
|
end
|
87
|
-
|
87
|
+
|
88
88
|
def to_ary
|
89
89
|
load_target.dup
|
90
90
|
end
|
91
91
|
alias_method :to_a, :to_ary
|
92
|
-
|
92
|
+
|
93
93
|
def <<(*records)
|
94
94
|
proxy_association.concat(records) && self
|
95
95
|
end
|
96
96
|
alias_method :push, :<<
|
97
|
-
|
97
|
+
|
98
98
|
def clear
|
99
99
|
destroy_all
|
100
100
|
self
|
101
101
|
end
|
102
|
-
|
102
|
+
|
103
103
|
def reload
|
104
104
|
proxy_association.reload
|
105
105
|
self
|
@@ -3,42 +3,42 @@ module DatastaxRails
|
|
3
3
|
module Associations
|
4
4
|
class HasAndBelongsToManyAssociation < CollectionAssociation #:nodoc:
|
5
5
|
attr_reader :join_name
|
6
|
-
|
6
|
+
|
7
7
|
def initialize(owner, reflection)
|
8
|
-
join_name = [owner.class.name.underscore, reflection.class_name.underscore].sort.join('_')
|
8
|
+
self.join_name = [owner.class.name.underscore, reflection.class_name.underscore].sort.join('_')
|
9
9
|
super
|
10
10
|
end
|
11
|
-
|
11
|
+
|
12
12
|
def insert_record(record, validate = true, raise = false)
|
13
13
|
if record.new_record?
|
14
14
|
if raise
|
15
|
-
record.save!(:
|
15
|
+
record.save!(validate: validate)
|
16
16
|
else
|
17
|
-
return unless record.save(:
|
17
|
+
return unless record.save(validate: validate)
|
18
18
|
end
|
19
19
|
end
|
20
|
-
|
21
|
-
left, right = [[record.class.name, record.id], [owner.class.name, owner.id]].sort {|a,b|b.first <=> a.first}
|
22
|
-
|
23
|
-
DatastaxRails::Base.connection.insert(join_column_family,
|
24
|
-
|
25
|
-
|
26
|
-
|
20
|
+
|
21
|
+
left, right = [[record.class.name, record.id], [owner.class.name, owner.id]].sort { |a, b|b.first <=> a.first }
|
22
|
+
|
23
|
+
DatastaxRails::Base.connection.insert(join_column_family,
|
24
|
+
SimpleUUID::UUID.new.to_guid,
|
25
|
+
left: "#{join_name}:#{left.last}",
|
26
|
+
right: "#{join_name}:#{right.last}")
|
27
27
|
end
|
28
|
-
|
29
|
-
|
28
|
+
|
30
29
|
private
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
30
|
+
|
31
|
+
def join_column_family
|
32
|
+
'many_to_many_joins'
|
33
|
+
end
|
34
|
+
|
35
|
+
def count_records
|
36
|
+
load_target.size
|
37
|
+
end
|
38
|
+
|
39
|
+
def invertible_for?(_record)
|
40
|
+
false
|
41
|
+
end
|
42
42
|
end
|
43
43
|
end
|
44
|
-
end
|
44
|
+
end
|
@@ -10,50 +10,50 @@ module DatastaxRails
|
|
10
10
|
set_inverse_instance(record)
|
11
11
|
|
12
12
|
if raise
|
13
|
-
record.save!(:
|
13
|
+
record.save!(validate: validate)
|
14
14
|
else
|
15
|
-
record.save(:
|
15
|
+
record.save(validate: validate)
|
16
16
|
end
|
17
17
|
end
|
18
|
-
|
18
|
+
|
19
19
|
private
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
20
|
+
|
21
|
+
# Returns the number of records in this collection.
|
22
|
+
#
|
23
|
+
# This does not depend on whether the collection has already been loaded
|
24
|
+
# or not. The +size+ method is the one that takes the loaded flag into
|
25
|
+
# account and delegates to +count_records+ if needed.
|
26
|
+
#
|
27
|
+
# If the collection is empty the target is set to an empty array and
|
28
|
+
# the loaded flag is set to true as well.
|
29
|
+
def count_records
|
30
|
+
count = scoped.count
|
31
|
+
|
32
|
+
# If there's nothing in the database and @target has no new records
|
33
|
+
# we are certain the current target is an empty array. This is a
|
34
|
+
# documented side-effect of the method that may avoid an extra SELECT.
|
35
|
+
@target ||= [] && loaded! if count == 0
|
36
|
+
|
37
|
+
count
|
38
|
+
end
|
39
|
+
|
40
|
+
# Deletes the records according to the <tt>:dependent</tt> option.
|
41
|
+
def delete_records(records, method)
|
42
|
+
if method == :destroy
|
43
|
+
records.each { |r| r.destroy }
|
44
|
+
else
|
45
|
+
keys = records.map { |r| r[reflection.association_primary_key] }
|
46
|
+
scope = scoped.where(reflection.association_primary_key => keys)
|
47
|
+
|
48
|
+
if method == :delete_all
|
49
|
+
scope.delete_all
|
44
50
|
else
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
if method == :delete_all
|
49
|
-
scope.delete_all
|
50
|
-
else
|
51
|
-
# This is for :nullify which isn't actually supported yet,
|
52
|
-
# but this should work once it is
|
53
|
-
scope.update_all(reflection.foreign_key => nil)
|
54
|
-
end
|
51
|
+
# This is for :nullify which isn't actually supported yet,
|
52
|
+
# but this should work once it is
|
53
|
+
scope.update_all(reflection.foreign_key => nil)
|
55
54
|
end
|
56
55
|
end
|
56
|
+
end
|
57
57
|
end
|
58
58
|
end
|
59
|
-
end
|
59
|
+
end
|
@@ -16,53 +16,52 @@ module DatastaxRails
|
|
16
16
|
if owner.persisted? && save && !record.save
|
17
17
|
nullify_owner_attributes(record)
|
18
18
|
set_owner_attributes(target) if target
|
19
|
-
|
19
|
+
fail RecordNotSaved, "Failed to save the new associated #{reflection.name}."
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
23
23
|
self.target = record
|
24
24
|
end
|
25
|
-
|
25
|
+
|
26
26
|
def delete(method = options[:dependent])
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
end
|
27
|
+
return unless load_target
|
28
|
+
case method
|
29
|
+
when :delete
|
30
|
+
target.delete
|
31
|
+
when :destroy
|
32
|
+
target.destroy
|
33
|
+
when :nullify
|
34
|
+
target.update_attribute(reflection.foreign_key, nil)
|
36
35
|
end
|
37
36
|
end
|
38
37
|
|
39
38
|
private
|
40
39
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
40
|
+
# The reason that the save param for replace is false, if for create (not just build),
|
41
|
+
# is because the setting of the foreign keys is actually handled by the scoping when
|
42
|
+
# the record is instantiated, and so they are set straight away and do not need to be
|
43
|
+
# updated within replace.
|
44
|
+
def set_new_record(record) # rubocop:disable Style/AccessorMethodName
|
45
|
+
replace(record, false)
|
46
|
+
end
|
48
47
|
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
48
|
+
def remove_target!(method)
|
49
|
+
if method.in?([:delete, :destroy])
|
50
|
+
target.send(method)
|
51
|
+
else
|
52
|
+
nullify_owner_attributes(target)
|
54
53
|
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
end
|
54
|
+
if target.persisted? && owner.persisted? && !target.save
|
55
|
+
set_owner_attributes(target)
|
56
|
+
fail RecordNotSaved, "Failed to remove the existing associated #{reflection.name}. " \
|
57
|
+
'The record failed to save when after its foreign key was set to nil.'
|
60
58
|
end
|
61
59
|
end
|
60
|
+
end
|
62
61
|
|
63
|
-
|
64
|
-
|
65
|
-
|
62
|
+
def nullify_owner_attributes(record)
|
63
|
+
record[reflection.foreign_key] = nil
|
64
|
+
end
|
66
65
|
end
|
67
66
|
end
|
68
|
-
end
|
67
|
+
end
|
@@ -6,16 +6,16 @@ module DatastaxRails
|
|
6
6
|
reload if force_reload || !loaded? || stale_target?
|
7
7
|
target
|
8
8
|
end
|
9
|
-
|
9
|
+
|
10
10
|
# Implements the writer method, e.g. foo.items= for Foo.has_many :items
|
11
11
|
def writer(record)
|
12
12
|
replace(record)
|
13
13
|
end
|
14
|
-
|
14
|
+
|
15
15
|
def create(attributes = {}, options = {}, &block)
|
16
16
|
create_record(attributes, options, &block)
|
17
17
|
end
|
18
|
-
|
18
|
+
|
19
19
|
def create!(attributes = {}, options = {}, &block)
|
20
20
|
create_record(attributes, options, true, &block)
|
21
21
|
end
|
@@ -26,33 +26,34 @@ module DatastaxRails
|
|
26
26
|
set_new_record(record)
|
27
27
|
record
|
28
28
|
end
|
29
|
-
|
29
|
+
|
30
30
|
private
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
31
|
+
|
32
|
+
def create_scope
|
33
|
+
scoped.scope_for_create.stringify_keys.except('id')
|
34
|
+
end
|
35
|
+
|
36
|
+
def find_target
|
37
|
+
scoped.first.tap { |record| set_inverse_instance(record) }
|
38
|
+
end
|
39
|
+
|
40
|
+
# Implemented by subclasses
|
41
|
+
def replace(_record)
|
42
|
+
fail NotImplementedError, 'Subclasses must implement a replace(record) method'
|
43
|
+
end
|
44
|
+
|
45
|
+
def set_new_record(record) # rubocop:disable Style/AccessorMethodName
|
46
|
+
replace(record)
|
47
|
+
end
|
48
|
+
|
49
|
+
def create_record(attributes, options, raise_error = false)
|
50
|
+
record = build_record(attributes, options)
|
51
|
+
yield(record) if block_given?
|
52
|
+
saved = record.save
|
53
|
+
set_new_record(record)
|
54
|
+
fail RecordInvalid.new(record) if !saved && raise_error
|
55
|
+
record
|
56
|
+
end
|
56
57
|
end
|
57
58
|
end
|
58
|
-
end
|
59
|
+
end
|
@@ -1,8 +1,10 @@
|
|
1
|
+
# rubocop:disable Style/PredicateName
|
1
2
|
module DatastaxRails
|
3
|
+
# Associations holds all the functionality related to DSR associations
|
2
4
|
module Associations
|
3
5
|
extend ActiveSupport::Concern
|
4
6
|
extend ActiveSupport::Autoload
|
5
|
-
|
7
|
+
|
6
8
|
autoload :Association
|
7
9
|
autoload :AssociationScope
|
8
10
|
autoload :SingularAssociation
|
@@ -11,19 +13,20 @@ module DatastaxRails
|
|
11
13
|
autoload :BelongsToAssociation
|
12
14
|
autoload :HasOneAssociation
|
13
15
|
autoload :HasManyAssociation
|
14
|
-
|
16
|
+
|
17
|
+
# Builder holds all the classes related to building the association
|
15
18
|
module Builder
|
16
19
|
extend ActiveSupport::Autoload
|
17
|
-
|
20
|
+
|
18
21
|
autoload :Association
|
19
22
|
autoload :SingularAssociation
|
20
23
|
autoload :CollectionAssociation
|
21
|
-
|
24
|
+
|
22
25
|
autoload :BelongsTo
|
23
26
|
autoload :HasOne
|
24
27
|
autoload :HasMany
|
25
28
|
end
|
26
|
-
|
29
|
+
|
27
30
|
# Clears out the association cache.
|
28
31
|
def clear_association_cache #:nodoc:
|
29
32
|
@association_cache.clear if persisted?
|
@@ -44,25 +47,26 @@ module DatastaxRails
|
|
44
47
|
|
45
48
|
association
|
46
49
|
end
|
47
|
-
|
50
|
+
|
48
51
|
private
|
49
|
-
# Returns the specified association instance if it responds to :loaded?, nil otherwise.
|
50
|
-
def association_instance_get(name)
|
51
|
-
@association_cache ||= {}
|
52
|
-
@association_cache[name.to_sym]
|
53
|
-
end
|
54
52
|
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
53
|
+
# Returns the specified association instance if it responds to :loaded?, nil otherwise.
|
54
|
+
def association_instance_get(name)
|
55
|
+
@association_cache ||= {}
|
56
|
+
@association_cache[name.to_sym]
|
57
|
+
end
|
58
|
+
|
59
|
+
# Set the specified association instance.
|
60
|
+
def association_instance_set(name, association)
|
61
|
+
@association_cache ||= {}
|
62
|
+
@association_cache[name] = association
|
63
|
+
end
|
64
|
+
|
61
65
|
module ClassMethods
|
62
66
|
def belongs_to(name, options = {})
|
63
67
|
Builder::BelongsTo.build(self, name, options)
|
64
68
|
end
|
65
|
-
|
69
|
+
|
66
70
|
def has_many(name, options = {})
|
67
71
|
Builder::HasMany.build(self, name, options)
|
68
72
|
# klass = options[:class_name]
|
@@ -70,17 +74,16 @@ module DatastaxRails
|
|
70
74
|
# foreign_key = options[:foreign_key]
|
71
75
|
# foreign_key ||= self.name.foreign_key
|
72
76
|
# define_method name do
|
73
|
-
|
77
|
+
# klass.where(foreign_key)
|
74
78
|
# end
|
75
79
|
end
|
76
|
-
|
77
|
-
def has_and_belongs_to_many(
|
78
|
-
|
80
|
+
|
81
|
+
def has_and_belongs_to_many(_name, _options = {})
|
79
82
|
end
|
80
|
-
|
83
|
+
|
81
84
|
def has_one(name, options = {})
|
82
85
|
Builder::HasOne.build(self, name, options)
|
83
86
|
end
|
84
87
|
end
|
85
88
|
end
|
86
|
-
end
|
89
|
+
end
|