Sha256: c05b40d4a560678e22d2ca7c663ee7d575b913d77f2bba7e210ea773ae2748c4

Contents?: true

Size: 1.56 KB

Versions: 24

Compression:

Stored size: 1.56 KB

Contents

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

    # TODO: is this the convention?
    include ActiveRecord::Reflection
    include ActiveRecord::Associations

    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

24 entries across 24 versions & 1 rubygems

Version Path
sessionm-cassandra_object-2.2.40 lib/cassandra_object/associations.rb
sessionm-cassandra_object-2.2.39 lib/cassandra_object/associations.rb
sessionm-cassandra_object-2.2.38 lib/cassandra_object/associations.rb
sessionm-cassandra_object-2.2.37 lib/cassandra_object/associations.rb
sessionm-cassandra_object-2.2.35 lib/cassandra_object/associations.rb
sessionm-cassandra_object-2.2.34 lib/cassandra_object/associations.rb
sessionm-cassandra_object-2.2.32 lib/cassandra_object/associations.rb
sessionm-cassandra_object-2.2.31 lib/cassandra_object/associations.rb
sessionm-cassandra_object-2.2.30 lib/cassandra_object/associations.rb
sessionm-cassandra_object-2.2.29 lib/cassandra_object/associations.rb
sessionm-cassandra_object-2.2.28 lib/cassandra_object/associations.rb
sessionm-cassandra_object-2.2.27 lib/cassandra_object/associations.rb
sessionm-cassandra_object-2.2.26 lib/cassandra_object/associations.rb
sessionm-cassandra_object-2.2.24 lib/cassandra_object/associations.rb
sessionm-cassandra_object-2.2.23 lib/cassandra_object/associations.rb
sessionm-cassandra_object-2.2.22 lib/cassandra_object/associations.rb
sessionm-cassandra_object-2.2.20 lib/cassandra_object/associations.rb
sessionm-cassandra_object-2.2.18 lib/cassandra_object/associations.rb
sessionm-cassandra_object-2.2.16 lib/cassandra_object/associations.rb
sessionm-cassandra_object-2.2.14 lib/cassandra_object/associations.rb