module Tenacity::OrmExt::ActiveRecord

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.

Public Class Methods

setup(model) click to toggle source
# 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