Class: OData::ActiveRecordSchema::NavigationProperty

Inherits:
OData::AbstractSchema::NavigationProperty show all
Defined in:
lib/o_data/active_record_schema/navigation_property.rb

Instance Attribute Summary

Attributes inherited from OData::AbstractSchema::NavigationProperty

#association, #entity_type, #from_end, #to_end

Attributes inherited from OData::AbstractSchema::SchemaObject

#name, #schema

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from OData::AbstractSchema::NavigationProperty

#return_type

Methods inherited from OData::AbstractSchema::SchemaObject

#<=>, #inspect, #plural_name, #qualified_name, #singular_name

Methods included from OData::AbstractSchema::Comparable

#compare, #sort

Constructor Details

#initialize(schema, entity_type, reflection) ⇒ NavigationProperty

Returns a new instance of NavigationProperty.



12
13
14
# File 'lib/o_data/active_record_schema/navigation_property.rb', line 12

def initialize(schema, entity_type, reflection)
  super(schema, entity_type, self.class.name_for(reflection), self.class.association_for(schema, reflection), :source => true)
end

Class Method Details

.association_for(schema, reflection) ⇒ Object



8
9
10
# File 'lib/o_data/active_record_schema/navigation_property.rb', line 8

def self.association_for(schema, reflection)
  schema.Association(reflection)
end

.name_for(reflection) ⇒ Object



4
5
6
# File 'lib/o_data/active_record_schema/navigation_property.rb', line 4

def self.name_for(reflection)
  reflection.name.to_s
end

Instance Method Details

#find_all(one, key_values = {}) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
# File 'lib/o_data/active_record_schema/navigation_property.rb', line 20

def find_all(one, key_values = {})
  results = one.send(method_name)
  unless key_values.blank?
    if results.respond_to?(:find)
      results = results.find(:all, :conditions => self.entity_type.conditions_for_find(key_values)) 
    else
      # TODO: raise exception if key_values supplied for non-finder method
    end
  end
  results
end

#find_one(one, key_value = nil) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
# File 'lib/o_data/active_record_schema/navigation_property.rb', line 32

def find_one(one, key_value = nil)
  results = one.send(method_name)
  unless key_value.blank?
    if results.respond_to?(:find)
      results = results.find(key_value)
    else
      # TODO: raise exception if key_value supplied for non-finder method
    end
  end
  results
end

#method_nameObject



16
17
18
# File 'lib/o_data/active_record_schema/navigation_property.rb', line 16

def method_name
  self.association.reflection.name.to_sym
end