Sha256: 60022b2f157c8c880dc3d497cdb7e1bf589389b6c67aa6e1a32cb7adac34302a

Contents?: true

Size: 1.45 KB

Versions: 47

Compression:

Stored size: 1.45 KB

Contents

module CassandraObject
  module Associations
    extend ActiveSupport::Concern
    extend ActiveSupport::Autoload

    autoload :OneToMany
    autoload :OneToOne
    
    included do
      class_inheritable_hash :associations
    end

    module ClassMethods
      def relationships_column_family=(column_family)
        @relationships_column_family = column_family
      end

      def relationships_column_family
        @relationships_column_family || "#{name}Relationships"
      end

      def column_family_configuration
        super << {:Name=>relationships_column_family, :CompareWith=>"UTF8Type", :CompareSubcolumnsWith=>"TimeUUIDType", :ColumnType=>"Super"}
      end

      def association(association_name, options= {})
        if options[:unique]
          write_inheritable_hash(:associations, {association_name => OneToOne.new(association_name, self, options)})
        else
          write_inheritable_hash(:associations, {association_name => OneToMany.new(association_name, self, options)})
        end
      end
      
      def remove(key)
        begin
          ActiveSupport::Notifications.instrument("remove.cassandra_object", column_family: relationships_column_family, key: key) do
            connection.remove(relationships_column_family, key.to_s, consistency: thrift_write_consistency)
          end
        rescue Cassandra::AccessError => e
          raise e unless e.message =~ /Invalid column family/
        end
        super
      end
    end
  end
end

Version data entries

47 entries across 47 versions & 1 rubygems

Version Path
gotime-cassandra_object-2.10.3 lib/cassandra_object/associations.rb
gotime-cassandra_object-2.10.2 lib/cassandra_object/associations.rb
gotime-cassandra_object-2.10.1 lib/cassandra_object/associations.rb
gotime-cassandra_object-2.10.0 lib/cassandra_object/associations.rb
gotime-cassandra_object-2.9.2 lib/cassandra_object/associations.rb
gotime-cassandra_object-2.9.1 lib/cassandra_object/associations.rb
gotime-cassandra_object-2.9.0 lib/cassandra_object/associations.rb
gotime-cassandra_object-2.8.6 lib/cassandra_object/associations.rb
gotime-cassandra_object-2.8.5 lib/cassandra_object/associations.rb
gotime-cassandra_object-2.8.4 lib/cassandra_object/associations.rb
gotime-cassandra_object-2.8.3 lib/cassandra_object/associations.rb
gotime-cassandra_object-2.8.2 lib/cassandra_object/associations.rb
gotime-cassandra_object-2.8.1 lib/cassandra_object/associations.rb
gotime-cassandra_object-2.8.0 lib/cassandra_object/associations.rb
gotime-cassandra_object-2.7.12 lib/cassandra_object/associations.rb
gotime-cassandra_object-2.7.11 lib/cassandra_object/associations.rb
gotime-cassandra_object-2.7.10 lib/cassandra_object/associations.rb
gotime-cassandra_object-2.7.9 lib/cassandra_object/associations.rb
gotime-cassandra_object-2.7.8 lib/cassandra_object/associations.rb
gotime-cassandra_object-2.7.7 lib/cassandra_object/associations.rb