Sha256: a564fdc58b7d983ae0b74cfc5317629e5efb91cda0104cf260980bc73f0fbe4d

Contents?: true

Size: 1.19 KB

Versions: 5

Compression:

Stored size: 1.19 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 column_family_configuration
        super << {:Name=>"#{name}Relationships", :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", :key => key) do
            connection.remove("#{name}Relationships", key.to_s, :consistency => write_consistency_for_thrift)
          end
        rescue Cassandra::AccessError => e
          raise e unless e.message =~ /Invalid column family/
        end
        super
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
gotime-cassandra_object-0.8.7 lib/cassandra_object/associations.rb
gotime-cassandra_object-0.8.6 lib/cassandra_object/associations.rb
gotime-cassandra_object-0.8.5 lib/cassandra_object/associations.rb
gotime-cassandra_object-0.8.4 lib/cassandra_object/associations.rb
gotime-cassandra_object-0.8.3 lib/cassandra_object/associations.rb