Module: Tenacity::OrmExt::Toystore

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

Overview

Tenacity relationships on Toystore objects require no special attributes defined on the object. Tenacity will define the attributes that it needs to support the relationships. Take the following class for example:

class Car
  include Toy::Store
  store :mongo, Mongo::Connection.new.db('tenacity')['toystore']
  include Tenacity

  t_has_many    :wheels
  t_has_one     :dashboard
  t_belongs_to  :driver
end

Please note that the data store must be established before including the Tenacity module.

t_belongs_to

The t_belongs_to association will define an attribute named after the association. The example above will create an attribute named :driver_id

t_has_one

The t_has_one association will not define any new attributes on the object, since the associated object holds the foreign key.

t_has_many

The t_has_many association will define an attribute named after the association. The example above will create attribute named :wheels_ids

Defined Under Namespace

Modules: ClassMethods, InstanceMethods

Class Method Summary collapse

Class Method Details

.setup(model) ⇒ Object

:nodoc:



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

def self.setup(model) #:nodoc:
  require 'toystore'
  if model.included_modules.include?(::Toy::Store)
    model.send :include, Toystore::InstanceMethods
    model.extend Toystore::ClassMethods
  end
rescue LoadError
  # Toystore not available
end