Module: Ardm::ActiveRecord::Associations::ClassMethods

Defined in:
lib/ardm/active_record/associations.rb

Instance Method Summary collapse

Instance Method Details

#belongs_to(field, options = {}) ⇒ Object



43
44
45
46
47
48
49
50
51
# File 'lib/ardm/active_record/associations.rb', line 43

def belongs_to(field, options={})
  options.delete(:default)
  options.delete(:required)
  opts = Ardm::ActiveRecord::Associations.convert_options(self, options)
  super field, opts
  assoc = reflect_on_association(field)
  property assoc.foreign_key, Ardm::Property::Integer
  nil
end

#has(count, name, *args) ⇒ Object



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/ardm/active_record/associations.rb', line 57

def has(count, name, *args)
  options = args.shift || {}

  if String === options # has n, :name, 'Class', options: 'here'
    options = (args.last || {}).merge(:model => options)
  end

  unless Hash === options
    raise ArgumentError, "bad has #{count} options format #{options.inspect}"
  end

  options[:order] = Ardm::ActiveRecord::Query.order(self, options[:order]) if options[:order]
  opts = Ardm::ActiveRecord::Associations.convert_options(self, options, :through, :order)

  case count
  when 1      then has_one  name, opts
  when "many" then has_many name, opts
  end
end

#nObject



53
54
55
# File 'lib/ardm/active_record/associations.rb', line 53

def n
  "many"
end