public
Fork of sam/dm-core
Description: DataMapper - Core
Homepage: http://datamapper.org
Clone URL: git://github.com/somebee/dm-core.git
somebee (author)
Wed May 14 18:08:25 -0700 2008
commit  1c7c5ba4893a9d19b3b84e95bb3f6f92de00f802
tree    d086b2ddb75adad02f00ffb91eb61cc4941a8029
parent  6160981583de998b75d7ae925c1864c77370e176
dm-core / lib / data_mapper / associations / many_to_many.rb
100644 41 lines (30 sloc) 1.243 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
module DataMapper
  module Associations
    module ManyToMany
      OPTIONS = [ :class_name, :child_key, :parent_key, :min, :max ]
 
      private
 
      def many_to_many(name, options = {})
        raise ArgumentError, "+name+ should be a Symbol, but was #{name.class}", caller unless Symbol === name
        raise ArgumentError, "+options+ should be a Hash, but was #{options.class}", caller unless Hash === options
 
        child_model_name = DataMapper::Inflection.demodulize(self.name)
        parent_model_name = options.fetch(:class_name, DataMapper::Inflection.classify(name))
 
        relationship = relationships(repository.name)[name] = Relationship.new(
          name,
          repository.name,
          child_model_name,
          parent_model_name,
          options
        )
 
        # TODO: add accessor/mutator to model with class_eval
 
        relationships
      end
 
      class Proxy
        instance_methods.each { |m| undef_method m unless %w[ __id__ __send__ class kind_of? should should_not ].include?(m) }
 
        def initialize() end
 
        def save
          raise NotImplementedError
        end
 
      end # class Proxy
    end # module ManyToMany
  end # module Associations
end # module DataMapper