Module: Tenacity::OrmExt::ActiveRecord

Defined in:
lib/tenacity/orm_ext/activerecord.rb

Overview

Tenacity relationships on ActiveRecord objects require that certain columns exist on the associated table. Take the following class for example:

class Car < ActiveRecord::Base
  include Tenacity

  t_has_many    :wheels
  t_has_one     :dashboard
  t_belongs_to  :driver
end

t_belongs_to

The t_belongs_to association requires that a property exist in the table to hold the id of the assoicated object.

create_table :cars do |t|
  t.string :driver_id
end

t_has_one

The t_has_one association requires no special column in the table, since the associated object holds the foreign key.

t_has_many

The t_has_many association requires nothing special, as the associates are looked up using the associate class.

Defined Under Namespace

Modules: ClassMethods, InstanceMethods

Class Method Summary collapse

Class Method Details

.setup(model) ⇒ Object



38
39
40
41
42
43
44
45
46
# File 'lib/tenacity/orm_ext/activerecord.rb', line 38

def self.setup(model)
  require 'active_record'
  if model.ancestors.include?(::ActiveRecord::Base)
    model.send :include, ActiveRecord::InstanceMethods
    model.extend ActiveRecord::ClassMethods
  end
rescue LoadError
  # ActiveRecord not available
end