public
Fork of sam/dm-core
Description: DataMapper - Core
Homepage: http://datamapper.org
Clone URL: git://github.com/thewordnerd/dm-core.git
Updated sepcs to use the Serial rather than Integer, :serial => true
dkubb (author)
Tue Jun 17 23:51:33 -0700 2008
commit  266988a22ce78d466b0f075d44f89a994c7accfb
tree    88f3c89977b9b8dabd7b4c48847666db5c1aa779
parent  942af3507cfea47f3fcff15d247674c00e02cec5
0
FAQ
...
7
8
9
10
 
11
12
13
...
36
37
38
39
 
40
41
42
...
7
8
9
 
10
11
12
13
...
36
37
38
 
39
40
41
42
0
@@ -7,7 +7,7 @@
0
 DataMapper will NOT create an auto-incrementing <tt>:id</tt> key for you
0
 automatically, so you'll need to either explicitly create one with
0
 
0
- property :id, Integer, :serial => true
0
+ property :id, Serial
0
 
0
 You can choose to use a natural key by doing
0
 
0
@@ -36,7 +36,7 @@ This is what the Discriminator data-type is for:
0
 
0
   class Person
0
     include DataMapper::Resource
0
- property :id, Integer, :serial => true
0
+ property :id, Serial
0
     property :type, Discriminator ## other shared properties here
0
   end
0
 
...
134
135
136
137
 
 
 
 
 
138
139
140
...
134
135
136
 
137
138
139
140
141
142
143
144
0
@@ -134,7 +134,11 @@ module DataMapper
0
           # TODO: move to dm-more/dm-migrations
0
           def property_schema_hash(repository, property)
0
             schema = super
0
- schema[:sequence_name] = sequence_name(repository, property) if property.serial?
0
+
0
+ if property.serial?
0
+ schema.delete(:default) # the sequence will be the default
0
+ schema[:sequence_name] = sequence_name(repository, property)
0
+ end
0
 
0
             # TODO: see if TypeMap can be updated to set specific attributes to nil
0
             # for different adapters. scale/precision are perfect examples for
...
161
162
163
164
 
165
166
167
...
161
162
163
 
164
165
166
167
0
@@ -161,7 +161,7 @@ module DataMapper
0
   #
0
   # Examples:
0
   #
0
- # property :id, Integer, :serial => true # auto-incrementing key
0
+ # property :id, Serial # auto-incrementing key
0
   # property :legacy_pk, String, :key => true # 'natural' key
0
   #
0
   # This is roughly equivalent to ActiveRecord's <tt>set_primary_key</tt>,
...
60
61
62
63
 
64
65
66
...
60
61
62
 
63
64
65
66
0
@@ -60,7 +60,7 @@ ARExhibit.find_by_sql('SELECT 1')
0
 class Exhibit
0
   include DataMapper::Resource
0
 
0
- property :id, Integer, :serial => true
0
+ property :id, Serial
0
   property :name, String
0
   property :zoo_id, Integer
0
   property :notes, Text, :lazy => true
...
26
27
28
29
 
30
31
32
...
26
27
28
 
29
30
31
32
0
@@ -26,7 +26,7 @@ DataMapper.setup(:default, "mysql://root@localhost/data_mapper_1?socket=#{SOCKET
0
 class Exhibit
0
   include DataMapper::Resource
0
 
0
- property :id, Integer, :serial => true
0
+ property :id, Serial
0
   property :name, String
0
   property :zoo_id, Integer
0
   property :notes, Text, :lazy => true
...
9
10
11
12
 
13
14
15
...
23
24
25
26
 
27
28
29
...
38
39
40
41
 
42
43
44
...
51
52
53
54
 
55
56
57
...
64
65
66
67
 
68
69
70
...
77
78
79
80
 
81
82
83
...
90
91
92
93
 
94
95
96
...
235
236
237
238
 
239
240
241
...
566
567
568
569
 
570
571
572
...
590
591
592
593
 
594
595
596
...
607
608
609
610
 
611
612
613
...
619
620
621
622
 
623
624
625
...
629
630
631
632
 
633
634
635
...
639
640
641
642
 
643
644
645
...
651
652
653
654
 
655
656
657
...
661
662
663
664
 
665
666
667
...
671
672
673
674
 
675
676
677
...
688
689
690
691
 
692
693
694
...
700
701
702
703
 
704
705
706
...
710
711
712
713
 
714
715
716
...
720
721
722
723
 
724
725
726
...
730
731
732
733
 
734
735
736
...
742
743
744
745
 
746
747
748
...
752
753
754
755
 
756
757
758
...
1039
1040
1041
1042
 
1043
1044
1045
...
1052
1053
1054
1055
 
1056
1057
1058
...
9
10
11
 
12
13
14
15
...
23
24
25
 
26
27
28
29
...
38
39
40
 
41
42
43
44
...
51
52
53
 
54
55
56
57
...
64
65
66
 
67
68
69
70
...
77
78
79
 
80
81
82
83
...
90
91
92
 
93
94
95
96
...
235
236
237
 
238
239
240
241
...
566
567
568
 
569
570
571
572
...
590
591
592
 
593
594
595
596
...
607
608
609
 
610
611
612
613
...
619
620
621
 
622
623
624
625
...
629
630
631
 
632
633
634
635
...
639
640
641
 
642
643
644
645
...
651
652
653
 
654
655
656
657
...
661
662
663
 
664
665
666
667
...
671
672
673
 
674
675
676
677
...
688
689
690
 
691
692
693
694
...
700
701
702
 
703
704
705
706
...
710
711
712
 
713
714
715
716
...
720
721
722
 
723
724
725
726
...
730
731
732
 
733
734
735
736
...
742
743
744
 
745
746
747
748
...
752
753
754
 
755
756
757
758
...
1039
1040
1041
 
1042
1043
1044
1045
...
1052
1053
1054
 
1055
1056
1057
1058
0
@@ -9,7 +9,7 @@ if ADAPTER
0
         ADAPTER
0
       end
0
 
0
- property :id, Integer, :serial => true
0
+ property :id, Serial
0
       property :name, String
0
 
0
       has n, :yards
0
@@ -23,7 +23,7 @@ if ADAPTER
0
         ADAPTER
0
       end
0
 
0
- property :id, Integer, :serial => true
0
+ property :id, Serial
0
       property :name, String
0
       property :rating, Integer
0
       property :type, String
0
@@ -38,7 +38,7 @@ if ADAPTER
0
         ADAPTER
0
       end
0
 
0
- property :id, Integer, :serial => true
0
+ property :id, Serial
0
       property :name, String
0
 
0
       belongs_to :sky
0
@@ -51,7 +51,7 @@ if ADAPTER
0
         ADAPTER
0
       end
0
 
0
- property :id, Integer, :serial => true
0
+ property :id, Serial
0
       property :name, String
0
 
0
       has 1, :pie
0
@@ -64,7 +64,7 @@ if ADAPTER
0
         ADAPTER
0
       end
0
 
0
- property :id, Integer, :serial => true
0
+ property :id, Serial
0
       property :name, String
0
 
0
       has n, :slices, :order => [:id.desc]
0
@@ -77,7 +77,7 @@ if ADAPTER
0
         ADAPTER
0
       end
0
 
0
- property :id, Integer, :serial => true
0
+ property :id, Serial
0
       property :name, String
0
 
0
       belongs_to :host
0
@@ -90,7 +90,7 @@ if ADAPTER
0
         ADAPTER
0
       end
0
 
0
- property :id, Integer, :serial => true
0
+ property :id, Serial
0
       property :name, String
0
 
0
       has n, :children, :class_name => 'Node', :child_key => [ :parent_id ]
0
@@ -235,7 +235,7 @@ if ADAPTER
0
           module FlightlessBirds
0
             class Ostrich
0
               include DataMapper::Resource
0
- property :id, Integer, :serial => true
0
+ property :id, Serial
0
               property :name, String
0
               belongs_to :sky # there's something sad about this :'(
0
             end
0
@@ -566,7 +566,7 @@ if ADAPTER
0
               def self.default_repository_name
0
                 ADAPTER
0
               end
0
- property :id, Integer, :serial => true
0
+ property :id, Serial
0
               property :name, String
0
               has n, :cakes, :class_name => 'Sweets::Cake' # has n
0
               has n, :recipes, :through => :cakes, :class_name => 'Sweets::Recipe' # has n => has 1
0
@@ -590,7 +590,7 @@ if ADAPTER
0
               def self.default_repository_name
0
                 ADAPTER
0
               end
0
- property :id, Integer, :serial => true
0
+ property :id, Serial
0
               property :name, String
0
               belongs_to :shop, :class_name => 'Sweets::Shop'
0
               has 1, :wife, :class_name => 'Sweets::Wife'
0
@@ -607,7 +607,7 @@ if ADAPTER
0
               def self.default_repository_name
0
                 ADAPTER
0
               end
0
- property :id, Integer, :serial => true
0
+ property :id, Serial
0
               property :name, String
0
               belongs_to :shop_owner, :class_name => 'Sweets::ShopOwner'
0
               has 1, :ring, :class_name => 'Sweets::Ring'
0
@@ -619,7 +619,7 @@ if ADAPTER
0
               def self.default_repository_name
0
                 ADAPTER
0
               end
0
- property :id, Integer, :serial => true
0
+ property :id, Serial
0
               property :name, String
0
               belongs_to :wife, :class_name => 'Sweets::Wife'
0
             end
0
@@ -629,7 +629,7 @@ if ADAPTER
0
               def self.default_repository_name
0
                 ADAPTER
0
               end
0
- property :id, Integer, :serial => true
0
+ property :id, Serial
0
               property :name, String
0
               belongs_to :wife, :class_name => 'Sweets::Wife'
0
             end
0
@@ -639,7 +639,7 @@ if ADAPTER
0
               def self.default_repository_name
0
                 ADAPTER
0
               end
0
- property :id, Integer, :serial => true
0
+ property :id, Serial
0
               property :name, String
0
               belongs_to :shop_owner, :class_name => 'Sweets::ShopOwner'
0
               has n, :toys, :class_name => 'Sweets::Toy'
0
@@ -651,7 +651,7 @@ if ADAPTER
0
               def self.default_repository_name
0
                 ADAPTER
0
               end
0
- property :id, Integer, :serial => true
0
+ property :id, Serial
0
               property :name, String
0
               belongs_to :child, :class_name => 'Sweets::Child'
0
             end
0
@@ -661,7 +661,7 @@ if ADAPTER
0
               def self.default_repository_name
0
                 ADAPTER
0
               end
0
- property :id, Integer, :serial => true
0
+ property :id, Serial
0
               property :name, String
0
               belongs_to :child, :class_name => 'Sweets::Child'
0
             end
0
@@ -671,7 +671,7 @@ if ADAPTER
0
               def self.default_repository_name
0
                 ADAPTER
0
               end
0
- property :id, Integer, :serial => true
0
+ property :id, Serial
0
               property :name, String
0
               belongs_to :shop, :class_name => 'Sweets::Shop'
0
               belongs_to :customer, :class_name => 'Sweets::Customer'
0
@@ -688,7 +688,7 @@ if ADAPTER
0
               def self.default_repository_name
0
                 ADAPTER
0
               end
0
- property :id, Integer, :serial => true
0
+ property :id, Serial
0
               property :name, String
0
               belongs_to :cake, :class_name => 'Sweets::Cake'
0
               has n, :ingredients, :class_name => 'Sweets::Ingredient'
0
@@ -700,7 +700,7 @@ if ADAPTER
0
               def self.default_repository_name
0
                 ADAPTER
0
               end
0
- property :id, Integer, :serial => true
0
+ property :id, Serial
0
               property :name, String
0
               has n, :cakes, :class_name => 'Sweets::Cake'
0
             end
0
@@ -710,7 +710,7 @@ if ADAPTER
0
               def self.default_repository_name
0
                 ADAPTER
0
               end
0
- property :id, Integer, :serial => true
0
+ property :id, Serial
0
               property :name, String
0
               belongs_to :recipe, :class_name => 'Sweets::Recipe'
0
             end
0
@@ -720,7 +720,7 @@ if ADAPTER
0
               def self.default_repository_name
0
                 ADAPTER
0
               end
0
- property :id, Integer, :serial => true
0
+ property :id, Serial
0
               property :name, String
0
               belongs_to :recipe, :class_name => 'Sweets::Recipe'
0
             end
0
@@ -730,7 +730,7 @@ if ADAPTER
0
               def self.default_repository_name
0
                 ADAPTER
0
               end
0
- property :id, Integer, :serial => true
0
+ property :id, Serial
0
               property :size, Integer
0
               belongs_to :cake, :class_name => 'Sweets::Cake'
0
               has n, :bites, :class_name => 'Sweets::Bite'
0
@@ -742,7 +742,7 @@ if ADAPTER
0
               def self.default_repository_name
0
                 ADAPTER
0
               end
0
- property :id, Integer, :serial => true
0
+ property :id, Serial
0
               property :name, String
0
               belongs_to :slice, :class_name => 'Sweets::Slice'
0
             end
0
@@ -752,7 +752,7 @@ if ADAPTER
0
               def self.default_repository_name
0
                 ADAPTER
0
               end
0
- property :id, Integer, :serial => true
0
+ property :id, Serial
0
               property :name, String
0
               belongs_to :slice, :class_name => 'Sweets::Slice'
0
             end
0
@@ -1039,7 +1039,7 @@ if ADAPTER
0
             ADAPTER
0
           end
0
 
0
- property :id, Integer, :serial => true
0
+ property :id, Serial
0
           property :name, String
0
 
0
           has n..n, :left_items
0
@@ -1052,7 +1052,7 @@ if ADAPTER
0
             ADAPTER
0
           end
0
 
0
- property :id, Integer, :serial => true
0
+ property :id, Serial
0
           property :name, String
0
 
0
           has n..n, :right_items
...
11
12
13
14
 
15
16
17
...
29
30
31
32
 
33
34
35
...
42
43
44
45
 
46
47
48
...
66
67
68
69
 
70
71
72
...
11
12
13
 
14
15
16
17
...
29
30
31
 
32
33
34
35
...
42
43
44
 
45
46
47
48
...
66
67
68
 
69
70
71
72
0
@@ -11,7 +11,7 @@ if ADAPTER
0
             ADAPTER
0
           end
0
 
0
- property :id, Integer, :serial => true
0
+ property :id, Serial
0
           property :title, String
0
           property :voided, Boolean, :default => false
0
 
0
@@ -29,7 +29,7 @@ if ADAPTER
0
             ADAPTER
0
           end
0
 
0
- property :id, Integer, :serial => true
0
+ property :id, Serial
0
           property :title, String
0
 
0
           belongs_to :post
0
@@ -42,7 +42,7 @@ if ADAPTER
0
             ADAPTER
0
           end
0
 
0
- property :id, Integer, :serial => true
0
+ property :id, Serial
0
           property :title, String
0
 
0
           has n, :taggings
0
@@ -66,7 +66,7 @@ if ADAPTER
0
             ADAPTER
0
           end
0
 
0
- property :id, Integer, :serial => true
0
+ property :id, Serial
0
           belongs_to :post
0
           belongs_to :related_post, :class_name => "Post"
0
         end
...
8
9
10
11
 
12
13
14
...
8
9
10
 
11
12
13
14
0
@@ -8,7 +8,7 @@ describe "ManyToMany" do
0
 
0
       def self.default_repository_name; ADAPTER end
0
 
0
- property :id, Integer, :serial => true
0
+ property :id, Serial
0
       property :name, String
0
 
0
       has n, :books, :through => Resource
...
18
19
20
21
 
22
23
24
...
41
42
43
44
 
45
46
47
...
18
19
20
 
21
22
23
24
...
41
42
43
 
44
45
46
47
0
@@ -18,7 +18,7 @@ TIME_4 = Time.parse(TIME_STRING_4)
0
 class EveryType
0
   include DataMapper::Resource
0
 
0
- property :serial, Integer, :serial => true
0
+ property :serial, Serial
0
   property :fixnum, Integer, :nullable => false, :default => 1
0
   property :string, String, :nullable => false, :default => 'default'
0
   property :empty, String, :nullable => false, :default => ''
0
@@ -41,7 +41,7 @@ end
0
 module Publications
0
   class ShortStoryCollection
0
     include DataMapper::Resource
0
- property :serial, Integer, :serial => true
0
+ property :serial, Serial
0
     property :date, Date, :nullable => false, :default => TODAY, :index => :date_date_time
0
   end
0
 end
...
8
9
10
11
 
12
13
14
...
23
24
25
26
 
27
28
29
...
8
9
10
 
11
12
13
14
...
23
24
25
 
26
27
28
29
0
@@ -8,7 +8,7 @@ if ADAPTER
0
       ADAPTER
0
     end
0
 
0
- property :id, Integer, :serial => true
0
+ property :id, Serial
0
     property :name, String
0
     property :age, Integer
0
     property :notes, Text
0
@@ -23,7 +23,7 @@ if ADAPTER
0
       ADAPTER
0
     end
0
 
0
- property :id, Integer, :serial => true
0
+ property :id, Serial
0
     property :name, String
0
     property :age, Integer
0
     property :zebra_id, Integer
...
10
11
12
13
 
14
15
16
...
10
11
12
 
13
14
15
16
0
@@ -10,7 +10,7 @@ if HAS_MYSQL
0
       class Sputnik
0
         include DataMapper::Resource
0
 
0
- property :id, Integer, :serial => true
0
+ property :id, Serial
0
         property :name, DM::Text
0
         property :object, Object
0
 
...
11
12
13
14
 
15
16
17
...
22
23
24
25
 
26
27
28
...
34
35
36
37
 
38
39
40
...
63
64
65
66
 
67
68
69
...
95
96
97
98
 
99
100
101
...
103
104
105
106
 
107
108
109
...
159
160
161
162
 
163
164
165
...
352
353
354
355
 
356
357
358
...
399
400
401
402
 
403
404
405
...
444
445
446
447
 
448
449
450
...
504
505
506
507
 
508
509
510
511
512
513
514
 
515
516
517
...
593
594
595
596
 
597
598
599
...
604
605
606
607
 
608
609
610
...
11
12
13
 
14
15
16
17
...
22
23
24
 
25
26
27
28
...
34
35
36
 
37
38
39
40
...
63
64
65
 
66
67
68
69
...
95
96
97
 
98
99
100
101
...
103
104
105
 
106
107
108
109
...
159
160
161
 
162
163
164
165
...
352
353
354
 
355
356
357
358
...
399
400
401
 
402
403
404
405
...
444
445
446
 
447
448
449
450
...
504
505
506
 
507
508
509
510
511
512
513
 
514
515
516
517
...
593
594
595
 
596
597
598
599
...
604
605
606
 
607
608
609
610
0
@@ -11,7 +11,7 @@ if HAS_POSTGRES
0
         class Sputnik
0
           include DataMapper::Resource
0
 
0
- property :id, Integer, :serial => true
0
+ property :id, Serial
0
           property :name, DM::Text
0
         end
0
       end
0
@@ -22,7 +22,7 @@ if HAS_POSTGRES
0
         Sputnik.auto_migrate!(:postgres)
0
         @adapter.storage_exists?("sputniks").should be_true
0
         @adapter.field_exists?("sputniks", "new_prop").should be_false
0
- Sputnik.property :new_prop, Integer, :serial => true
0
+ Sputnik.property :new_prop, DM::Serial
0
         @adapter.send(:drop_sequence, repository(:postgres), Sputnik.new_prop)
0
         Sputnik.auto_upgrade!(:postgres)
0
         @adapter.field_exists?("sputniks", "new_prop").should == true
0
@@ -34,7 +34,7 @@ if HAS_POSTGRES
0
         class Sputnik
0
           include DataMapper::Resource
0
 
0
- property :id, Integer, :serial => true
0
+ property :id, Serial
0
           property :name, DM::Text
0
         end
0
 
0
@@ -63,7 +63,7 @@ if HAS_POSTGRES
0
         class Sputnik
0
           include DataMapper::Resource
0
 
0
- property :id, Integer, :serial => true
0
+ property :id, Serial
0
           property :name, DM::Text
0
         end
0
 
0
@@ -95,7 +95,7 @@ if HAS_POSTGRES
0
         class User
0
           include DataMapper::Resource
0
 
0
- property :id, Integer, :serial => true
0
+ property :id, Serial
0
           property :name, DM::Text
0
         end
0
 
0
@@ -103,7 +103,7 @@ if HAS_POSTGRES
0
           include DataMapper::Resource
0
           storage_names[:postgres] = 'sattellites.voyagers'
0
 
0
- property :id, Integer, :serial => true
0
+ property :id, Serial
0
           property :age, Integer
0
         end
0
 
0
@@ -159,7 +159,7 @@ if HAS_POSTGRES
0
         class VideoGame
0
           include DataMapper::Resource
0
 
0
- property :id, Integer, :serial => true
0
+ property :id, Serial
0
           property :name, String
0
           property :object, Object
0
         end
0
@@ -352,7 +352,7 @@ if HAS_POSTGRES
0
       before :all do
0
         class SailBoat
0
           include DataMapper::Resource
0
- property :id, Integer, :serial => true
0
+ property :id, Serial
0
           property :name, String
0
           property :port, String
0
         end
0
@@ -399,7 +399,7 @@ if HAS_POSTGRES
0
       before :all do
0
         class SailBoat
0
           include DataMapper::Resource
0
- property :id, Integer, :serial => true
0
+ property :id, Serial
0
           property :notes, String, :lazy => [:notes]
0
           property :trip_report, String, :lazy => [:notes,:trip]
0
           property :miles, Integer, :lazy => [:trip]
0
@@ -444,7 +444,7 @@ if HAS_POSTGRES
0
         class SerialFinderSpec
0
           include DataMapper::Resource
0
 
0
- property :id, Integer, :serial => true
0
+ property :id, Serial
0
           property :sample, String
0
         end
0
       end
0
@@ -504,14 +504,14 @@ if HAS_POSTGRES
0
         class Engine
0
           include DataMapper::Resource
0
 
0
- property :id, Integer, :serial => true
0
+ property :id, Serial
0
           property :name, String
0
         end
0
 
0
         class Yard
0
           include DataMapper::Resource
0
 
0
- property :id, Integer, :serial => true
0
+ property :id, Serial
0
           property :name, String
0
           property :engine_id, Integer
0
 
0
@@ -593,7 +593,7 @@ if HAS_POSTGRES
0
         class Host
0
           include DataMapper::Resource
0
 
0
- property :id, Integer, :serial => true
0
+ property :id, Serial
0
           property :name, String
0
 
0
           repository(:postgres) do
0
@@ -604,7 +604,7 @@ if HAS_POSTGRES
0
         class Slice
0
           include DataMapper::Resource
0
 
0
- property :id, Integer, :serial => true
0
+ property :id, Serial
0
           property :name, String
0
           property :host_id, Integer
0
 
0