class DataMapper::Associations::OneToOne::Relationship

Attributes

relationship[R]

Public Class Methods

new(name, target_model, source_model, options = {}) click to toggle source

Initializes the relationship. Always assumes target model class is a camel cased association name.

@api semipublic

# File lib/dm-core/associations/one_to_one.rb, line 73
def initialize(name, target_model, source_model, options = {})
  klass = options.key?(:through) ? ManyToMany::Relationship : OneToMany::Relationship
  target_model ||= DataMapper::Inflector.camelize(name).freeze
  @relationship = klass.new(name, target_model, source_model, options)
end

Public Instance Methods

default_for(source) click to toggle source

@api semipublic

# File lib/dm-core/associations/one_to_one.rb, line 46
def default_for(source)
  relationship.default_for(source).first
end
get(source, query = nil) click to toggle source

Loads (if necessary) and returns association target for given source

@api semipublic

# File lib/dm-core/associations/one_to_one.rb, line 18
def get(source, query = nil)
  relationship.get(source, query).first
end
get!(source) click to toggle source

Get the resource directly

@api semipublic

# File lib/dm-core/associations/one_to_one.rb, line 25
def get!(source)
  collection = relationship.get!(source)
  collection.first if collection
end
instance_of?(klass) click to toggle source

@api public

Calls superclass method
# File lib/dm-core/associations/one_to_one.rb, line 56
def instance_of?(klass)
  super || relationship.instance_of?(klass)
end
kind_of?(klass) click to toggle source

@api public

Calls superclass method
# File lib/dm-core/associations/one_to_one.rb, line 51
def kind_of?(klass)
  super || relationship.kind_of?(klass)
end
respond_to?(method, include_private = false) click to toggle source

@api public

Calls superclass method
# File lib/dm-core/associations/one_to_one.rb, line 61
def respond_to?(method, include_private = false)
  super || relationship.respond_to?(method, include_private)
end
set(source, target) click to toggle source

Sets and returns association target for given source

@api semipublic

# File lib/dm-core/associations/one_to_one.rb, line 34
def set(source, target)
  relationship.set(source, [ target ].compact).first
end
set!(source, target) click to toggle source

Sets the resource directly

@api semipublic

# File lib/dm-core/associations/one_to_one.rb, line 41
def set!(source, target)
  set(source, target)
end

Private Instance Methods

method_missing(method, *args, &block) click to toggle source

@api private

# File lib/dm-core/associations/one_to_one.rb, line 80
def method_missing(method, *args, &block)
  relationship.send(method, *args, &block)
end