Module: Upmin::DataMapper::Association

Defined in:
lib/upmin/data_mapper/association.rb

Instance Method Summary collapse

Instance Method Details

#collection?Boolean

Returns:

  • (Boolean)


33
34
35
36
37
38
39
40
41
# File 'lib/upmin/data_mapper/association.rb', line 33

def collection?
  if relationship
    return relationship.max > 1
  elsif value
    return value.responts_to?(:each)
  else
    return false
  end
end

#typeObject



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/upmin/data_mapper/association.rb', line 4

def type
  return @type if defined?(@type)

  if relationship
    # NOTE(jon): I believe many to one is the only type where child_model_name is incorrect, but I could be wrong.
    if relationship.is_a?(DataMapper::Associations::ManyToOne::Relationship)
      @type = relationship.parent_model_name
    else
      @type = relationship.child_model_name
    end

    @type = @type.underscore

    if collection?
      @type = @type.pluralize.to_sym
    else
      @type = @type.to_sym
    end
  else
    @type = :unknown
  end

  if @type == :unknown
    @type = infer_type_from_value
  end

  return @type
end