Class: ActiveRecord::ConnectionAdapters::SalesforceRelationship

Inherits:
Object
  • Object
show all
Includes:
StringHelper
Defined in:
lib/active_record/connection_adapters/relationship_definition.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from StringHelper

#column_nameize

Constructor Details

#initialize(source, column = nil) ⇒ SalesforceRelationship

Returns a new instance of SalesforceRelationship.



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/active_record/connection_adapters/relationship_definition.rb', line 35

def initialize(source, column = nil)
  if source[:childSObject]
    relationship = source
    
    if relationship[:relationshipName]
      @api_name = relationship[:relationshipName]
      @one_to_many = true
      @label = @api_name
      @name = column_nameize(@api_name)
      @custom = false
    else 
      @api_name = relationship[:field]
      @one_to_many = relationship[:cascadeDelete] == "true"
      @label = relationship[:childSObject].pluralize
      @custom = relationship[:childSObject].match(/__c$/)

      name = relationship[:childSObject]
      name = name.chop.chop.chop if custom
      
      @name = column_nameize(name.pluralize)
      @name = @name + "__c" if custom
    end
    
    @reference_to = relationship[:childSObject]
    
    @foreign_key = column_nameize(relationship[:field])
    @foreign_key = @foreign_key.chop.chop << "id__c" if @foreign_key.match(/__c$/)
  else
    field = source
    
    @api_name = field[:name]
    @custom = field[:custom] == "true"
    
    @api_name = @api_name.chop.chop unless @custom
    
    @label = field[:label]
    @reference_to = field[:referenceTo]
    @one_to_many = false
    
    @foreign_key = column.name
    @name = column_nameize(@api_name)
  end
end

Instance Attribute Details

#api_nameObject (readonly)

Returns the value of attribute api_name.



33
34
35
# File 'lib/active_record/connection_adapters/relationship_definition.rb', line 33

def api_name
  @api_name
end

#customObject (readonly)

Returns the value of attribute custom.



33
34
35
# File 'lib/active_record/connection_adapters/relationship_definition.rb', line 33

def custom
  @custom
end

#foreign_keyObject (readonly)

Returns the value of attribute foreign_key.



33
34
35
# File 'lib/active_record/connection_adapters/relationship_definition.rb', line 33

def foreign_key
  @foreign_key
end

#labelObject (readonly)

Returns the value of attribute label.



33
34
35
# File 'lib/active_record/connection_adapters/relationship_definition.rb', line 33

def label
  @label
end

#nameObject (readonly)

Returns the value of attribute name.



33
34
35
# File 'lib/active_record/connection_adapters/relationship_definition.rb', line 33

def name
  @name
end

#one_to_manyObject (readonly)

Returns the value of attribute one_to_many.



33
34
35
# File 'lib/active_record/connection_adapters/relationship_definition.rb', line 33

def one_to_many
  @one_to_many
end

#reference_toObject (readonly)

Returns the value of attribute reference_to.



33
34
35
# File 'lib/active_record/connection_adapters/relationship_definition.rb', line 33

def reference_to
  @reference_to
end