class RareMap::Relation

RareMap::Relation defines one of has_one, has_many and has_many_through relations of a database table. @author Wei-Ming Wu @!attribute [r] type

@return [Symbol] the type of relation, `:has_one` or `:has_many` or `:has_many_through`

@!attribute [r] foreign_key

@return [String] the foreign key of this Relation based on

@!attribute [r] table

@return [String] the table of this Relation refers to

@!attribute [r] through

@return [String, nil] the table of this Relation goes through

Constants

BELONGS_TO

The :belongs_to association.

HAS_MANY

The :has_many association.

HAS_MANY_THROUGH

The :has_many_through association.

HAS_ONE

The :has_one association.

RELATIONS

All three kinds of relations

Attributes

foreign_key[R]
table[R]
through[R]
type[R]

Public Class Methods

new(type, foreign_key, table, through = nil) click to toggle source

Creates a Relation.

@param type [Symbol] the type, ‘:has_one` or `:has_many` or `:has_many_through` @param foreign_key [String] the foreign key of this Relation based on @param table [String] the table of this Relation refers to @param through [String, nil] the table of this Relation goes through @return [Relation] the Relation object

# File lib/rare_map/relation.rb, line 36
def initialize(type, foreign_key, table, through = nil)
  raise RelationNotDefinedError, 'Relation type not defined.' unless RELATIONS.include? type
  @type, @foreign_key, @table, @through = type, foreign_key, table, through
end