Sha256: dde11e4f8fc21f374cbfa19a0523217955f0b3db465d353aaa792551d4a869a3
Contents?: true
Size: 1.3 KB
Versions: 4
Compression:
Stored size: 1.3 KB
Contents
module MongoidExt module MongoMapper extend ActiveSupport::Concern included do end module ClassMethods def find_each(*args, &block) all(*args).each do |doc| block.call(doc) end end def many(name, opts = {}) opts[:stored_as] = :array if opts.delete(:in) if fkey = opts.delete(:foreign_key) opts[:inverse_of] = fkey.sub(/_id$/, "") end references_many name, opts end alias :has_many :many def one(name, opts = {}) if fkey = opts.delete(:foreign_key) opts[:inverse_of] = fkey.sub(/_id$/, "") end references_one name, opts end alias :has_one :one def belongs_to(name, opts = {}) if fkey = opts.delete(:foreign_key) opts[:inverse_of] = fkey.sub(/_id$/, "") end if opts[:polymorphic] raise ArgumentError, "polymorphic associations are not supported yet" end referenced_in name, opts end def timestamps! include Mongoid::Timestamps end def key(name, *args) opts = args.extract_options! opts[:type] = args.first if !args.empty? field name, opts end def ensure_index(*args) index *args end end end end
Version data entries
4 entries across 4 versions & 1 rubygems