datastax_rails 2.0.12 → 2.0.15
Sign up to get free protection for your applications and to get access to all the features.
- 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
data/lib/datastax_rails/base.rb
CHANGED
@@ -77,7 +77,7 @@ module DatastaxRails #:nodoc:
|
|
77
77
|
# sense to sort on anyways).
|
78
78
|
#
|
79
79
|
# EXAMPLE:
|
80
|
-
#
|
80
|
+
#
|
81
81
|
# class Person < DatastaxRails::Base
|
82
82
|
# uuid :id
|
83
83
|
# string :first_name
|
@@ -233,15 +233,15 @@ module DatastaxRails #:nodoc:
|
|
233
233
|
# Company.where(name: 'All*').first #=> finds the first company whose name begins with All
|
234
234
|
#
|
235
235
|
# See DatastaxRails::FinderMethods for more information
|
236
|
-
#
|
236
|
+
#
|
237
237
|
# == Facets
|
238
238
|
#
|
239
239
|
# DSR support both field and range facets. For additional detail on facets, see the documentation
|
240
|
-
# available under the {DatastaxRails::FacetMethods} module. The result is available through the
|
240
|
+
# available under the {DatastaxRails::FacetMethods} module. The result is available through the
|
241
241
|
# facets accessor.
|
242
242
|
#
|
243
243
|
# results = Article.field_facet(:author)
|
244
|
-
# results.facets #=> {"author"=>["vonnegut", 2. "asimov", 3]}
|
244
|
+
# results.facets #=> {"author"=>["vonnegut", 2. "asimov", 3]}
|
245
245
|
#
|
246
246
|
# Model.field_facet(:author)
|
247
247
|
# Model.field_facet(:author, sort: 'count', limit: 10, mincount: 1)
|
@@ -273,7 +273,7 @@ module DatastaxRails #:nodoc:
|
|
273
273
|
# will lose data.
|
274
274
|
#
|
275
275
|
# === Set
|
276
|
-
#
|
276
|
+
#
|
277
277
|
# A set is an un-ordered collection of unique values. This collection is fully searchable in Solr.
|
278
278
|
#
|
279
279
|
# class User < DatastaxRails::Base
|
@@ -296,7 +296,7 @@ module DatastaxRails #:nodoc:
|
|
296
296
|
# user.emails #=> ['jim@example.com']
|
297
297
|
#
|
298
298
|
# === List
|
299
|
-
#
|
299
|
+
#
|
300
300
|
# An ordered collection of values. They do not necessarily have to be unique. The collection
|
301
301
|
# will be fully searchable in Solr.
|
302
302
|
#
|
@@ -346,10 +346,9 @@ module DatastaxRails #:nodoc:
|
|
346
346
|
#
|
347
347
|
# See the documentation for {DatastaxRails::SearchMethods} for more examples of using the search API.
|
348
348
|
class Base
|
349
|
-
|
350
|
-
include ActiveModel::Conversion
|
349
|
+
include ActiveModel::Model
|
351
350
|
extend ActiveSupport::DescendantsTracker
|
352
|
-
|
351
|
+
|
353
352
|
include Persistence
|
354
353
|
include Connection
|
355
354
|
include Inheritance
|
@@ -365,15 +364,15 @@ module DatastaxRails #:nodoc:
|
|
365
364
|
include Timestamps
|
366
365
|
include Serialization
|
367
366
|
include SolrRepair
|
368
|
-
|
367
|
+
|
369
368
|
# Stores the default scope for the class
|
370
|
-
class_attribute :default_scopes, :
|
369
|
+
class_attribute :default_scopes, instance_writer: false
|
371
370
|
self.default_scopes = []
|
372
|
-
|
371
|
+
|
373
372
|
# Stores the connection configuration information
|
374
373
|
class_attribute :config
|
375
|
-
|
376
|
-
class_attribute :default_timezone, :
|
374
|
+
|
375
|
+
class_attribute :default_timezone, instance_writer: false
|
377
376
|
self.default_timezone = :utc
|
378
377
|
|
379
378
|
# Stores the default consistency level (QUORUM by default)
|
@@ -383,45 +382,45 @@ module DatastaxRails #:nodoc:
|
|
383
382
|
# Stores the method of saving data (CQL by default)
|
384
383
|
class_attribute :storage_method
|
385
384
|
self.storage_method = :cql
|
386
|
-
|
385
|
+
|
387
386
|
# Stores any additional information that should be used when creating the column family
|
388
387
|
# See {DatastaxRails::WideStorageModel} or {DatastaxRails::Payload} model for an example
|
389
388
|
class_attribute :create_options
|
390
|
-
|
389
|
+
|
391
390
|
# Stores the attribute that wide models should cluster on. Basically, this is the
|
392
391
|
# attribute that CQL uses to "group" columns into logical records even though they
|
393
392
|
# are stored on the same row.
|
394
393
|
class_attribute :cluster_by
|
395
|
-
|
394
|
+
|
396
395
|
attr_reader :attributes
|
397
396
|
attr_reader :loaded_attributes
|
398
397
|
attr_accessor :key
|
399
|
-
|
398
|
+
|
400
399
|
# Returns a hash of all the attributes that have been specified for serialization as
|
401
400
|
# keys and their class restriction as values.
|
402
401
|
class_attribute :serialized_attributes
|
403
402
|
self.serialized_attributes = {}
|
404
|
-
|
403
|
+
|
405
404
|
# Whether or not we are using solr legacy mappings
|
406
405
|
class_attribute :legacy_mapping
|
407
|
-
|
408
|
-
def initialize(attributes = {},
|
406
|
+
|
407
|
+
def initialize(attributes = {}, _options = {})
|
409
408
|
defaults = self.class.column_defaults.dup
|
410
|
-
defaults.each { |
|
411
|
-
|
412
|
-
@attributes =
|
409
|
+
defaults.each { |_k, v| v.duplicable? ? v.dup : v }
|
410
|
+
|
411
|
+
@attributes = initialize_attributes(defaults)
|
413
412
|
@column_types = self.class.columns_hash
|
414
413
|
|
415
414
|
init_internals
|
416
|
-
init_changed_attributes
|
415
|
+
init_changed_attributes
|
417
416
|
populate_with_current_scope_attributes
|
418
|
-
|
417
|
+
|
419
418
|
assign_attributes(attributes) if attributes
|
420
|
-
|
419
|
+
|
421
420
|
yield self if block_given?
|
422
421
|
run_callbacks :initialize unless _initialize_callbacks.empty?
|
423
422
|
end
|
424
|
-
|
423
|
+
|
425
424
|
# Initialize an empty model object from +coder+. +coder+ must contain
|
426
425
|
# the attributes necessary for initializing an empty model object. For
|
427
426
|
# example:
|
@@ -434,35 +433,35 @@ module DatastaxRails #:nodoc:
|
|
434
433
|
# post.title # => 'hello world'
|
435
434
|
def init_with(coder)
|
436
435
|
Types::DirtyCollection.ignore_modifications do
|
437
|
-
@attributes =
|
436
|
+
@attributes = initialize_attributes(coder['attributes'])
|
438
437
|
@column_types_override = coder['column_types']
|
439
438
|
@column_types = self.class.columns_hash
|
440
|
-
|
439
|
+
|
441
440
|
init_internals
|
442
|
-
|
441
|
+
|
443
442
|
@new_record = false
|
444
443
|
run_callbacks :find
|
445
444
|
run_callbacks :initialize
|
446
445
|
end
|
447
446
|
self
|
448
447
|
end
|
449
|
-
|
448
|
+
|
450
449
|
def init_internals
|
451
450
|
pk = self.class.primary_key
|
452
451
|
@attributes[pk] = nil unless @attributes.key?(pk)
|
453
452
|
|
454
453
|
@association_cache = {}
|
455
454
|
@attributes_cache = {}
|
456
|
-
@previously_changed = {}
|
457
|
-
@changed_attributes = {}
|
458
|
-
@loaded_attributes = Hash[@attributes.map{|k,
|
455
|
+
@previously_changed = {}.with_indifferent_access
|
456
|
+
@changed_attributes = {}.with_indifferent_access
|
457
|
+
@loaded_attributes = Hash[@attributes.map { |k, _v| [k, true] }].with_indifferent_access
|
459
458
|
@readonly = false
|
460
459
|
@destroyed = false
|
461
460
|
@marked_for_destruction = false
|
462
461
|
@destroyed_by_association = nil
|
463
462
|
@new_record = true
|
464
463
|
end
|
465
|
-
|
464
|
+
|
466
465
|
def init_changed_attributes
|
467
466
|
# Intentionally avoid using #column_defaults since overridden defaults
|
468
467
|
# won't get written unless they get marked as changed
|
@@ -471,17 +470,18 @@ module DatastaxRails #:nodoc:
|
|
471
470
|
@changed_attributes[attr] = orig_value if _field_changed?(attr, orig_value, @attributes[attr])
|
472
471
|
end
|
473
472
|
end
|
474
|
-
|
473
|
+
|
475
474
|
# Freeze the attributes hash such that associations are still accessible, even on destroyed records.
|
476
475
|
def freeze
|
477
|
-
@attributes.freeze
|
476
|
+
@attributes.freeze
|
477
|
+
self
|
478
478
|
end
|
479
479
|
|
480
480
|
# Returns +true+ if the attributes hash has been frozen.
|
481
481
|
def frozen?
|
482
482
|
@attributes.frozen?
|
483
483
|
end
|
484
|
-
|
484
|
+
|
485
485
|
def to_param
|
486
486
|
id.to_s if persisted?
|
487
487
|
end
|
@@ -490,52 +490,51 @@ module DatastaxRails #:nodoc:
|
|
490
490
|
id.hash
|
491
491
|
end
|
492
492
|
|
493
|
-
def ==(
|
493
|
+
def ==(other)
|
494
494
|
super ||
|
495
|
-
|
495
|
+
other.instance_of?(self.class) &&
|
496
496
|
id.present? &&
|
497
|
-
|
497
|
+
other.id.eql?(id)
|
498
498
|
end
|
499
499
|
|
500
|
-
def eql?(
|
501
|
-
self == (
|
500
|
+
def eql?(other)
|
501
|
+
self == (other)
|
502
502
|
end
|
503
|
-
|
503
|
+
|
504
504
|
def attribute_names
|
505
505
|
self.class.attribute_names
|
506
506
|
end
|
507
|
-
|
508
|
-
|
507
|
+
alias_method :column_names, :attribute_names
|
508
|
+
|
509
509
|
def valid_consistency?(level) #:nodoc:
|
510
510
|
self.class.validate_consistency(level.to_s.upcase)
|
511
511
|
end
|
512
|
-
|
512
|
+
|
513
513
|
private
|
514
|
-
|
515
|
-
|
516
|
-
|
517
|
-
|
518
|
-
|
519
|
-
|
514
|
+
|
515
|
+
def populate_with_current_scope_attributes
|
516
|
+
return unless self.class.scope_attributes?
|
517
|
+
|
518
|
+
self.class.scope_attributes.each do |att, value|
|
519
|
+
send("#{att}=", value) if respond_to?("#{att}=")
|
520
520
|
end
|
521
|
-
|
521
|
+
end
|
522
|
+
|
522
523
|
class << self
|
523
|
-
delegate :find, :find_by, :find_by!, :first, :all, :exists?, :any?, :many?, :
|
524
|
-
delegate :destroy, :destroy_all, :delete, :update, :update_all, :
|
525
|
-
delegate :order, :limit, :where, :where_not, :page, :paginate, :select, :slow_order, :
|
526
|
-
delegate :per_page, :each, :group, :total_pages, :search, :fulltext, :
|
527
|
-
delegate :count, :first, :first!, :last, :last!, :compute_stats, :
|
528
|
-
delegate :sum, :average, :minimum, :maximum, :stddev, :
|
529
|
-
delegate :cql, :with_cassandra, :with_solr, :commit_solr, :allow_filtering, :
|
530
|
-
delegate :find_each, :find_in_batches, :consistency, :
|
531
|
-
delegate :field_facet, :range_facet, :
|
524
|
+
delegate :find, :find_by, :find_by!, :first, :all, :exists?, :any?, :many?, to: :scoped
|
525
|
+
delegate :destroy, :destroy_all, :delete, :update, :update_all, to: :scoped
|
526
|
+
delegate :order, :limit, :where, :where_not, :page, :paginate, :select, :slow_order, to: :scoped
|
527
|
+
delegate :per_page, :each, :group, :total_pages, :search, :fulltext, to: :scoped
|
528
|
+
delegate :count, :first, :first!, :last, :last!, :compute_stats, to: :scoped
|
529
|
+
delegate :sum, :average, :minimum, :maximum, :stddev, to: :scoped
|
530
|
+
delegate :cql, :with_cassandra, :with_solr, :commit_solr, :allow_filtering, to: :scoped
|
531
|
+
delegate :find_each, :find_in_batches, :consistency, to: :scoped
|
532
|
+
delegate :field_facet, :range_facet, to: :scoped
|
532
533
|
|
533
534
|
# Sets the column family name
|
534
535
|
#
|
535
536
|
# @param [String] column_family the name of the column family in cassandra
|
536
|
-
|
537
|
-
@column_family = column_family
|
538
|
-
end
|
537
|
+
attr_writer :column_family
|
539
538
|
|
540
539
|
# Returns the column family name. If it has been set manually, the set name is returned.
|
541
540
|
# Otherwise returns the pluralized version of the class name.
|
@@ -544,51 +543,49 @@ module DatastaxRails #:nodoc:
|
|
544
543
|
def column_family
|
545
544
|
@column_family || name.underscore.pluralize
|
546
545
|
end
|
547
|
-
|
546
|
+
|
548
547
|
def models
|
549
|
-
|
548
|
+
descendants.reject { |m|m.abstract_class? }
|
550
549
|
end
|
551
|
-
|
550
|
+
|
552
551
|
def payload_model?
|
553
|
-
|
552
|
+
ancestors.include?(DatastaxRails::PayloadModel)
|
554
553
|
end
|
555
|
-
|
554
|
+
|
556
555
|
def wide_storage_model?
|
557
|
-
|
556
|
+
ancestors.include?(DatastaxRails::WideStorageModel)
|
558
557
|
end
|
559
|
-
|
558
|
+
|
560
559
|
def legacy_mapping?
|
561
|
-
|
560
|
+
legacy_mapping
|
562
561
|
end
|
563
|
-
|
562
|
+
|
564
563
|
def base_class
|
565
564
|
klass = self
|
566
|
-
while klass.superclass != Base
|
567
|
-
klass = klass.superclass
|
568
|
-
end
|
565
|
+
klass = klass.superclass while klass.superclass != Base
|
569
566
|
klass
|
570
567
|
end
|
571
|
-
|
568
|
+
|
572
569
|
def find_by_id(id)
|
573
570
|
scoped.with_cassandra.find(id)
|
574
571
|
rescue RecordNotFound
|
575
572
|
nil
|
576
573
|
end
|
577
|
-
|
574
|
+
|
578
575
|
def logger
|
579
576
|
Rails.logger
|
580
577
|
end
|
581
|
-
|
578
|
+
|
582
579
|
# Returns an array of attribute names as strings
|
583
580
|
def attribute_names
|
584
|
-
@attribute_names ||= attribute_definitions.keys.
|
581
|
+
@attribute_names ||= attribute_definitions.keys.map { |a|a.to_s }
|
585
582
|
end
|
586
|
-
|
587
|
-
|
583
|
+
alias_method :column_names, :attribute_names
|
584
|
+
|
588
585
|
def columns
|
589
586
|
@columns ||= attribute_definitions.values
|
590
587
|
end
|
591
|
-
|
588
|
+
|
592
589
|
# SOLR always paginates all requests. There is no way to disable it, so we are
|
593
590
|
# setting the default page size to an arbitrarily high number so that we effectively
|
594
591
|
# remove pagination. If you instead want a model set to something more sane, then
|
@@ -601,18 +598,18 @@ module DatastaxRails #:nodoc:
|
|
601
598
|
# end
|
602
599
|
# end
|
603
600
|
def default_page_size
|
604
|
-
|
601
|
+
100_000
|
605
602
|
end
|
606
|
-
|
603
|
+
|
607
604
|
def search_ids(&block)
|
608
605
|
search = solr_search(&block)
|
609
606
|
search.raw_results.map { |result| result.primary_key }
|
610
607
|
end
|
611
|
-
|
608
|
+
|
612
609
|
def valid_consistency?(level) #:nodoc:
|
613
610
|
DatastaxRails::Cql::Consistency::VALID_CONSISTENCY_LEVELS.include?(level)
|
614
611
|
end
|
615
|
-
|
612
|
+
|
616
613
|
# Returns a string like 'Post(id:integer, title:string, body:text)'
|
617
614
|
def inspect
|
618
615
|
if self == Base
|
@@ -622,45 +619,45 @@ module DatastaxRails #:nodoc:
|
|
622
619
|
"#{super}(#{attr_list})"
|
623
620
|
end
|
624
621
|
end
|
625
|
-
|
622
|
+
|
626
623
|
private
|
627
|
-
|
628
|
-
def construct_finder_relation(options = {}, scope = nil)
|
629
|
-
relation = options.is_a?(Hash) ? unscoped.apply_finder_options(options) : options
|
630
|
-
relation = scope.merge(relation) if scope
|
631
|
-
relation
|
632
|
-
end
|
633
|
-
|
634
|
-
def relation #:nodoc:
|
635
|
-
Relation.new(self, column_family)
|
636
|
-
end
|
637
|
-
|
638
|
-
# Returns the class type of the record using the current module as a prefix. So descendants of
|
639
|
-
# MyApp::Business::Account would appear as MyApp::Business::AccountSubclass.
|
640
|
-
def compute_type(type_name)
|
641
|
-
if type_name.match(/^::/)
|
642
|
-
# If the type is prefixed with a scope operator then we assume that
|
643
|
-
# the type_name is an absolute reference.
|
644
|
-
ActiveSupport::Dependencies.constantize(type_name)
|
645
|
-
else
|
646
|
-
# Build a list of candidates to search for
|
647
|
-
candidates = []
|
648
|
-
name.scan(/::|$/) { candidates.unshift "#{$`}::#{type_name}" }
|
649
|
-
candidates << type_name
|
650
|
-
|
651
|
-
candidates.each do |candidate|
|
652
|
-
begin
|
653
|
-
constant = ActiveSupport::Dependencies.constantize(candidate)
|
654
|
-
return constant if candidate == constant.to_s
|
655
|
-
rescue NameError => e
|
656
|
-
# We don't want to swallow NoMethodError < NameError errors
|
657
|
-
raise e unless e.instance_of?(NameError)
|
658
|
-
end
|
659
|
-
end
|
660
624
|
|
661
|
-
|
625
|
+
def construct_finder_relation(options = {}, scope = nil)
|
626
|
+
relation = options.is_a?(Hash) ? unscoped.apply_finder_options(options) : options
|
627
|
+
relation = scope.merge(relation) if scope
|
628
|
+
relation
|
629
|
+
end
|
630
|
+
|
631
|
+
def relation #:nodoc:
|
632
|
+
Relation.new(self, column_family)
|
633
|
+
end
|
634
|
+
|
635
|
+
# Returns the class type of the record using the current module as a prefix. So descendants of
|
636
|
+
# MyApp::Business::Account would appear as MyApp::Business::AccountSubclass.
|
637
|
+
def compute_type(type_name)
|
638
|
+
if type_name.match(/^::/)
|
639
|
+
# If the type is prefixed with a scope operator then we assume that
|
640
|
+
# the type_name is an absolute reference.
|
641
|
+
ActiveSupport::Dependencies.constantize(type_name)
|
642
|
+
else
|
643
|
+
# Build a list of candidates to search for
|
644
|
+
candidates = []
|
645
|
+
name.scan(/::|$/) { candidates.unshift "#{$`}::#{type_name}" }
|
646
|
+
candidates << type_name
|
647
|
+
|
648
|
+
candidates.each do |candidate|
|
649
|
+
begin
|
650
|
+
constant = ActiveSupport::Dependencies.constantize(candidate)
|
651
|
+
return constant if candidate == constant.to_s
|
652
|
+
rescue NameError => e
|
653
|
+
# We don't want to swallow NoMethodError < NameError errors
|
654
|
+
raise e unless e.instance_of?(NameError)
|
655
|
+
end
|
662
656
|
end
|
657
|
+
|
658
|
+
fail NameError, "uninitialized constant #{candidates.first}"
|
663
659
|
end
|
660
|
+
end
|
664
661
|
end
|
665
662
|
end
|
666
663
|
end
|