Module: Model::BelongsTo::ClassMethods

Defined in:
app/models/concerns/model/belongs_to.rb

Instance Method Summary collapse

Instance Method Details

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



6
7
8
9
10
11
12
13
# File 'app/models/concerns/model/belongs_to.rb', line 6

def belongs_to(name, options = {})
  id_attr = "#{name}_id"

  belongs_to_reader id_attr, name, options
  belongs_to_writer id_attr, name, options

  validates name, presence: true unless options[:optional]
end