Module: Filemaker::Model::Fields

Extended by:
ActiveSupport::Concern
Included in:
Components
Defined in:
lib/filemaker/model/fields.rb

Overview

‘Fields` help to give `Model` their perceived schema. To find out your fields, use `Model.fm_fields` or use Rails generator like:

rails generate filemaker:model filename database layout

Examples:

class Model
  include Filemaker::Model

  string :id, identity: true
  string :title, fm_name: 'A_Title', default: 'Untitled'
  money  :salary
end

Defined Under Namespace

Modules: ClassMethods

Constant Summary collapse

TYPE_MAPPINGS =
{
  string:     String,
  text:       String,
  date:       Date,
  datetime:   DateTime,
  money:      BigDecimal,
  number:     BigDecimal,
  integer:    Integer,
  email:      Filemaker::Model::Types::Email,
  object:     Filemaker::Model::Types::Attachment
}.freeze

Instance Method Summary collapse

Instance Method Details

#apply_defaultsObject

Apply default value when you instantiate a new model.



41
42
43
44
45
46
# File 'lib/filemaker/model/fields.rb', line 41

def apply_defaults
  attribute_names.each do |name|
    field = fields[name]
    attributes[name] = field.default_value
  end
end

#attribute_namesObject



48
49
50
# File 'lib/filemaker/model/fields.rb', line 48

def attribute_names
  self.class.attribute_names
end

#fm_namesObject



52
53
54
# File 'lib/filemaker/model/fields.rb', line 52

def fm_names
  fields.values.map(&:fm_name)
end