Class: Drupal::CCK::ContentNodeFieldInstance

Inherits:
Object
  • Object
show all
Defined in:
lib/drupal/cck.rb

Instance Method Summary collapse

Instance Method Details

#fieldObject



36
37
38
# File 'lib/drupal/cck.rb', line 36

def field
  @field ||= ContentNodeField.first :field_name => field_name
end

#field_typeObject



40
41
42
# File 'lib/drupal/cck.rb', line 40

def field_type
  @field_type ||= field.type
end

#through?Boolean

Returns:

  • (Boolean)


72
73
74
# File 'lib/drupal/cck.rb', line 72

def through?
  Drupal::CCK::Builder.fields.include? "content_#{field_name}"
end

#to_sObject



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
# File 'lib/drupal/cck.rb', line 44

def to_s
  f = field_name.match(/^field_(.*)/)[1]
  case field_type
  when 'userreference'
    if through?
      r = "has 1, :#{f},
             :class_name => Drupal::#{f.camel_case},
             :child_key => [:nid]
           
           has 1, :#{f}_user,
             :remote_name => :user,
             :class_name => Drupal::User,
             :child_key => [:nid],
             :through => :#{f}"
    else
      r = "belongs_to :#{field_name},
        :class_name => 'Drupal::User'"
    end
  when 'number_integer'
    r  = "property :#{f}, Integer, 
            :field => 'field_#{f}_value'"
  when 'text'
    r  = "property :#{f}, Text, 
            :field => 'field_#{f}_value'"
  end
  r
end