Module: RiakRecord::Associations

Included in:
Base
Defined in:
lib/riak_record/associations.rb

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



74
75
76
# File 'lib/riak_record/associations.rb', line 74

def self.included(base)
  base.extend(ClassMethods)
end

Instance Method Details



18
19
20
# File 'lib/riak_record/associations.rb', line 18

def link_definitions
  self.class.link_definitions
end


4
5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/riak_record/associations.rb', line 4

def update_links
  link_definitions.each_pair do |tag, definition|
    tag = tag.to_s
    bucket_name = Object.const_get(definition[:class_name].to_s).bucket_name.to_s
    key = self.send(definition[:foreign_key].to_sym).first

    # remove links with tag name
    self.links.delete_if{|l| l.tag.to_s == tag }

    # add link if key is set
    self.links << Riak::Link.new(bucket_name.to_s, key.to_s, tag.to_s) unless key.nil?
  end
end