module Consort::ActiveRecord::Mongoid::ClassMethods

Public Instance Methods

active_record_consorts_with_mongoid?() click to toggle source

Allows easy validation of whether ActiveRecord to Mongoid bridge is loaded. @return [Boolean] `true` if bridge is loaded

# File lib/consort/active_record/mongoid.rb, line 64
def active_record_consorts_with_mongoid?
  true
end
belongs_to_mongoid(klass) click to toggle source

Defines a `belongs_to` relationship with a Mongoid object. An appropriate foreign key column (of type String) must exist on your model. @param klass [Symbol] @example Migration

class AddMongoidFKeyToNarwhals < ActiveRecord::Migration
  def change
    add_column :narwhals, :pod_id, :string
  end
end

@example Model

class Narwhal < ActiveRecord::Base
  belongs_to_mongoid :pod
end
# File lib/consort/active_record/mongoid.rb, line 54
        def belongs_to_mongoid(klass)
          class_eval <<-CODE
            def #{klass}
              #{klass.to_s.classify}.where(id: #{klass.to_s.foreign_key})
            end
          CODE
        end
has_many_mongoid(klass) click to toggle source

Defines a `has_many` relationship with a Mongoid object. @param klass [Symbol] @example

has_many_mongoid :unicorns

@since 0.0.2

# File lib/consort/active_record/mongoid.rb, line 27
        def has_many_mongoid(klass)
          class_eval <<-CODE
            def #{klass}
              #{klass.to_s.classify}.where(#{name.foreign_key}: id)
            end
          CODE
        end
has_many_mongoids(klass) click to toggle source

@deprecated Use {#has_many_mongoid} instead. Will be removed in 1.0.0.

# File lib/consort/active_record/mongoid.rb, line 36
def has_many_mongoids(klass)
  ActiveSupport::Deprecation.warn 'Please use the singular has_many_mongoid instead.'
  has_many_mongoid(klass)
end
has_one_mongoid(klass) click to toggle source

Defines a `has_one` relationship with a Mongoid object. @param klass [Symbol] @example

has_one_mongoid :dolphin
# File lib/consort/active_record/mongoid.rb, line 14
        def has_one_mongoid(klass)
          class_eval <<-CODE
            def #{klass}
              #{klass.to_s.classify}.where(#{name.foreign_key}: id)
            end
          CODE
        end