Skip to content

Commit

Permalink
Backwards compatibility: adding embedded and associations back
Browse files Browse the repository at this point in the history
  • Loading branch information
durran committed Jan 5, 2011
1 parent 3db7551 commit cf29221
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions lib/mongoid/relations/macros.rb
Expand Up @@ -8,12 +8,23 @@ module Macros
extend ActiveSupport::Concern

included do
cattr_accessor :embedded
class_inheritable_accessor :relations
self.embedded = false
self.relations = {}

# For backwards compatibility, alias the class method for associations
# and embedding as well. Fix in related gems.
#
# @todo Affected libraries: Machinist
class << self
alias :associations :relations
alias :embedded? :embedded
end

# Convenience methods for the instance to know about attributes that
# are located at the class level.
delegate :relations, :to => "self.class"
delegate :associations, :relations, :to => "self.class"
end

module ClassMethods #:nodoc:
Expand All @@ -39,10 +50,10 @@ module ClassMethods #:nodoc:
# @param [ Hash ] options The relation options.
# @param [ Proc ] block Optional block for defining extensions.
def embedded_in(name, options = {}, &block)
relate(
name,
metadatafy(name, Embedded::In, options, &block)
)
metadatafy(name, Embedded::In, options, &block).tap do |meta|
self.embedded = true
relate(name, meta)
end
end

# Adds the relation from a parent document to its children. The name
Expand Down

0 comments on commit cf29221

Please sign in to comment.