globe-composite_primary_keys 3.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (150) hide show
  1. data/History.txt +203 -0
  2. data/Manifest.txt +121 -0
  3. data/README.txt +41 -0
  4. data/README_DB2.txt +33 -0
  5. data/Rakefile +30 -0
  6. data/composite_primary_keys.gemspec +17 -0
  7. data/lib/adapter_helper/base.rb +63 -0
  8. data/lib/adapter_helper/mysql.rb +13 -0
  9. data/lib/adapter_helper/oracle.rb +12 -0
  10. data/lib/adapter_helper/oracle_enhanced.rb +12 -0
  11. data/lib/adapter_helper/postgresql.rb +13 -0
  12. data/lib/adapter_helper/sqlite3.rb +13 -0
  13. data/lib/composite_primary_keys.rb +63 -0
  14. data/lib/composite_primary_keys/association_preload.rb +162 -0
  15. data/lib/composite_primary_keys/associations.rb +159 -0
  16. data/lib/composite_primary_keys/attribute_methods.rb +84 -0
  17. data/lib/composite_primary_keys/base.rb +200 -0
  18. data/lib/composite_primary_keys/composite_arrays.rb +29 -0
  19. data/lib/composite_primary_keys/connection_adapters/abstract_adapter.rb +9 -0
  20. data/lib/composite_primary_keys/connection_adapters/ibm_db_adapter.rb +21 -0
  21. data/lib/composite_primary_keys/connection_adapters/oracle_adapter.rb +15 -0
  22. data/lib/composite_primary_keys/connection_adapters/oracle_enhanced_adapter.rb +17 -0
  23. data/lib/composite_primary_keys/connection_adapters/postgresql_adapter.rb +53 -0
  24. data/lib/composite_primary_keys/connection_adapters/sqlite3_adapter.rb +15 -0
  25. data/lib/composite_primary_keys/finder_methods.rb +68 -0
  26. data/lib/composite_primary_keys/fixtures.rb +8 -0
  27. data/lib/composite_primary_keys/read.rb +25 -0
  28. data/lib/composite_primary_keys/reflection.rb +39 -0
  29. data/lib/composite_primary_keys/relation.rb +31 -0
  30. data/lib/composite_primary_keys/through_association_scope.rb +212 -0
  31. data/lib/composite_primary_keys/validations/uniqueness.rb +118 -0
  32. data/lib/composite_primary_keys/version.rb +9 -0
  33. data/loader.rb +24 -0
  34. data/local/database_connections.rb.sample +12 -0
  35. data/local/paths.rb.sample +2 -0
  36. data/local/tasks.rb.sample +2 -0
  37. data/scripts/console.rb +48 -0
  38. data/scripts/txt2html +67 -0
  39. data/scripts/txt2js +59 -0
  40. data/tasks/activerecord_selection.rake +43 -0
  41. data/tasks/databases.rake +12 -0
  42. data/tasks/databases/mysql.rake +30 -0
  43. data/tasks/databases/oracle.rake +25 -0
  44. data/tasks/databases/postgresql.rake +25 -0
  45. data/tasks/databases/sqlite3.rake +28 -0
  46. data/tasks/deployment.rake +22 -0
  47. data/tasks/local_setup.rake +13 -0
  48. data/tasks/website.rake +18 -0
  49. data/test/README_tests.txt +67 -0
  50. data/test/abstract_unit.rb +103 -0
  51. data/test/connections/native_ibm_db/connection.rb +23 -0
  52. data/test/connections/native_mysql/connection.rb +13 -0
  53. data/test/connections/native_oracle/connection.rb +14 -0
  54. data/test/connections/native_oracle_enhanced/connection.rb +20 -0
  55. data/test/connections/native_postgresql/connection.rb +8 -0
  56. data/test/connections/native_sqlite/connection.rb +9 -0
  57. data/test/fixtures/article.rb +5 -0
  58. data/test/fixtures/article_group.rb +4 -0
  59. data/test/fixtures/article_groups.yml +7 -0
  60. data/test/fixtures/articles.yml +6 -0
  61. data/test/fixtures/comment.rb +6 -0
  62. data/test/fixtures/comments.yml +16 -0
  63. data/test/fixtures/db_definitions/db2-create-tables.sql +113 -0
  64. data/test/fixtures/db_definitions/db2-drop-tables.sql +16 -0
  65. data/test/fixtures/db_definitions/mysql.sql +181 -0
  66. data/test/fixtures/db_definitions/oracle.drop.sql +39 -0
  67. data/test/fixtures/db_definitions/oracle.sql +188 -0
  68. data/test/fixtures/db_definitions/postgresql.sql +206 -0
  69. data/test/fixtures/db_definitions/sqlite.sql +166 -0
  70. data/test/fixtures/department.rb +5 -0
  71. data/test/fixtures/departments.yml +3 -0
  72. data/test/fixtures/dorm.rb +3 -0
  73. data/test/fixtures/dorms.yml +2 -0
  74. data/test/fixtures/employee.rb +4 -0
  75. data/test/fixtures/employees.yml +9 -0
  76. data/test/fixtures/group.rb +3 -0
  77. data/test/fixtures/groups.yml +3 -0
  78. data/test/fixtures/hack.rb +6 -0
  79. data/test/fixtures/hacks.yml +2 -0
  80. data/test/fixtures/kitchen_sink.rb +3 -0
  81. data/test/fixtures/kitchen_sinks.yml +5 -0
  82. data/test/fixtures/membership.rb +10 -0
  83. data/test/fixtures/membership_status.rb +3 -0
  84. data/test/fixtures/membership_statuses.yml +10 -0
  85. data/test/fixtures/memberships.yml +6 -0
  86. data/test/fixtures/product.rb +7 -0
  87. data/test/fixtures/product_tariff.rb +5 -0
  88. data/test/fixtures/product_tariffs.yml +12 -0
  89. data/test/fixtures/products.yml +6 -0
  90. data/test/fixtures/reading.rb +4 -0
  91. data/test/fixtures/readings.yml +10 -0
  92. data/test/fixtures/reference_code.rb +7 -0
  93. data/test/fixtures/reference_codes.yml +28 -0
  94. data/test/fixtures/reference_type.rb +7 -0
  95. data/test/fixtures/reference_types.yml +9 -0
  96. data/test/fixtures/restaurant.rb +6 -0
  97. data/test/fixtures/restaurants.yml +5 -0
  98. data/test/fixtures/restaurants_suburbs.yml +11 -0
  99. data/test/fixtures/room.rb +10 -0
  100. data/test/fixtures/room_assignment.rb +4 -0
  101. data/test/fixtures/room_assignments.yml +4 -0
  102. data/test/fixtures/room_attribute.rb +3 -0
  103. data/test/fixtures/room_attribute_assignment.rb +5 -0
  104. data/test/fixtures/room_attribute_assignments.yml +4 -0
  105. data/test/fixtures/room_attributes.yml +3 -0
  106. data/test/fixtures/rooms.yml +3 -0
  107. data/test/fixtures/seat.rb +5 -0
  108. data/test/fixtures/seats.yml +4 -0
  109. data/test/fixtures/street.rb +3 -0
  110. data/test/fixtures/streets.yml +15 -0
  111. data/test/fixtures/student.rb +4 -0
  112. data/test/fixtures/students.yml +2 -0
  113. data/test/fixtures/suburb.rb +6 -0
  114. data/test/fixtures/suburbs.yml +9 -0
  115. data/test/fixtures/tariff.rb +6 -0
  116. data/test/fixtures/tariffs.yml +13 -0
  117. data/test/fixtures/user.rb +10 -0
  118. data/test/fixtures/users.yml +6 -0
  119. data/test/hash_tricks.rb +34 -0
  120. data/test/plugins/pagination.rb +405 -0
  121. data/test/plugins/pagination_helper.rb +135 -0
  122. data/test/test_associations.rb +178 -0
  123. data/test/test_attribute_methods.rb +22 -0
  124. data/test/test_attributes.rb +80 -0
  125. data/test/test_clone.rb +34 -0
  126. data/test/test_composite_arrays.rb +32 -0
  127. data/test/test_create.rb +68 -0
  128. data/test/test_delete.rb +83 -0
  129. data/test/test_exists.rb +25 -0
  130. data/test/test_find.rb +73 -0
  131. data/test/test_ids.rb +90 -0
  132. data/test/test_miscellaneous.rb +39 -0
  133. data/test/test_pagination.rb +38 -0
  134. data/test/test_polymorphic.rb +32 -0
  135. data/test/test_santiago.rb +27 -0
  136. data/test/test_suite.rb +19 -0
  137. data/test/test_tutorial_example.rb +26 -0
  138. data/test/test_update.rb +40 -0
  139. data/test/test_validations.rb +11 -0
  140. data/website/index.html +195 -0
  141. data/website/index.txt +159 -0
  142. data/website/javascripts/rounded_corners_lite.inc.js +285 -0
  143. data/website/stylesheets/screen.css +126 -0
  144. data/website/template.js +3 -0
  145. data/website/template.rhtml +53 -0
  146. data/website/version-raw.js +3 -0
  147. data/website/version-raw.txt +2 -0
  148. data/website/version.js +4 -0
  149. data/website/version.txt +3 -0
  150. metadata +339 -0
@@ -0,0 +1,166 @@
1
+ create table reference_types (
2
+ reference_type_id integer primary key,
3
+ type_label varchar(50) default null,
4
+ abbreviation varchar(50) default null,
5
+ description varchar(50) default null
6
+ );
7
+
8
+ create table reference_codes (
9
+ reference_type_id int(11),
10
+ reference_code int(11) not null,
11
+ code_label varchar(50) default null,
12
+ abbreviation varchar(50) default null,
13
+ description varchar(50) default null,
14
+ primary key (reference_type_id, reference_code)
15
+ );
16
+
17
+ create table products (
18
+ id int(11) not null primary key,
19
+ name varchar(50) default null
20
+ );
21
+
22
+ create table tariffs (
23
+ tariff_id int(11) not null,
24
+ start_date date not null,
25
+ amount integer(11) default null,
26
+ primary key (tariff_id, start_date)
27
+ );
28
+
29
+ create table product_tariffs (
30
+ product_id int(11) not null,
31
+ tariff_id int(11) not null,
32
+ tariff_start_date date not null,
33
+ primary key (product_id, tariff_id, tariff_start_date)
34
+ );
35
+
36
+ create table suburbs (
37
+ city_id int(11) not null,
38
+ suburb_id int(11) not null,
39
+ name varchar(50) not null,
40
+ primary key (city_id, suburb_id)
41
+ );
42
+
43
+ create table streets (
44
+ id integer not null primary key autoincrement,
45
+ city_id int(11) not null,
46
+ suburb_id int(11) not null,
47
+ name varchar(50) not null
48
+ );
49
+
50
+ create table users (
51
+ id integer not null primary key autoincrement,
52
+ name varchar(50) not null
53
+ );
54
+
55
+ create table articles (
56
+ id integer not null primary key autoincrement,
57
+ name varchar(50) not null
58
+ );
59
+
60
+ create table readings (
61
+ id integer not null primary key autoincrement,
62
+ user_id int(11) not null,
63
+ article_id int(11) not null,
64
+ rating int(11) not null
65
+ );
66
+
67
+ create table groups (
68
+ id integer not null primary key autoincrement,
69
+ name varchar(50) not null
70
+ );
71
+
72
+ create table memberships (
73
+ user_id int not null,
74
+ group_id int not null,
75
+ primary key (user_id, group_id)
76
+ );
77
+
78
+ create table membership_statuses (
79
+ id integer not null primary key autoincrement,
80
+ user_id int not null,
81
+ group_id int not null,
82
+ status varchar(50) not null
83
+ );
84
+
85
+ create table departments (
86
+ department_id integer not null,
87
+ location_id integer not null,
88
+ primary key (department_id, location_id)
89
+ );
90
+
91
+ create table employees (
92
+ id integer not null primary key autoincrement,
93
+ department_id integer null,
94
+ location_id integer null
95
+ );
96
+
97
+ create table comments (
98
+ id integer not null primary key autoincrement,
99
+ person_id varchar(100) null,
100
+ person_type varchar(100) null,
101
+ hack_id varchar(100) null
102
+ );
103
+
104
+ create table hacks (
105
+ name varchar(50) not null primary key
106
+ );
107
+
108
+ create table kitchen_sinks (
109
+ id_1 integer not null,
110
+ id_2 integer not null,
111
+ a_date date,
112
+ a_string varchar(100),
113
+ primary key (id_1, id_2)
114
+ );
115
+
116
+ create table restaurants (
117
+ franchise_id integer not null,
118
+ store_id integer not null,
119
+ name varchar(100),
120
+ primary key (franchise_id, store_id)
121
+ );
122
+
123
+ create table restaurants_suburbs (
124
+ franchise_id integer not null,
125
+ store_id integer not null,
126
+ city_id integer not null,
127
+ suburb_id integer not null
128
+ );
129
+
130
+ create table dorms (
131
+ id integer not null primary key autoincrement
132
+ );
133
+
134
+ create table rooms (
135
+ dorm_id integer not null,
136
+ room_id integer not null,
137
+ primary key (dorm_id, room_id)
138
+ );
139
+
140
+ create table room_attributes (
141
+ id integer not null primary key autoincrement,
142
+ name varchar(50)
143
+ );
144
+
145
+ create table room_attribute_assignments (
146
+ dorm_id integer not null,
147
+ room_id integer not null,
148
+ room_attribute_id integer not null
149
+ );
150
+
151
+ create table students (
152
+ id integer not null primary key autoincrement
153
+ );
154
+
155
+ create table room_assignments (
156
+ student_id integer not null,
157
+ dorm_id integer not null,
158
+ room_id integer not null
159
+ );
160
+
161
+ create table seats (
162
+ flight_number integer not_null,
163
+ seat integer not_null,
164
+ customer integer,
165
+ primary key (flight_number, seat)
166
+ );
@@ -0,0 +1,5 @@
1
+ class Department < ActiveRecord::Base
2
+ # set_primary_keys *keys - turns on composite key functionality
3
+ set_primary_keys :department_id, :location_id
4
+ has_many :employees, :foreign_key => [:department_id, :location_id]
5
+ end
@@ -0,0 +1,3 @@
1
+ department1-cpk:
2
+ department_id: 1
3
+ location_id: 1
@@ -0,0 +1,3 @@
1
+ class Dorm < ActiveRecord::Base
2
+ has_many :rooms, :include => :room_attributes
3
+ end
@@ -0,0 +1,2 @@
1
+ jacksons_dorm:
2
+ id: 1
@@ -0,0 +1,4 @@
1
+ class Employee < ActiveRecord::Base
2
+ belongs_to :department, :foreign_key => [:department_id, :location_id]
3
+ has_many :comments, :as => :person
4
+ end
@@ -0,0 +1,9 @@
1
+ employee1:
2
+ id: 1
3
+ department_id: 1
4
+ location_id: 1
5
+ employee2:
6
+ id: 2
7
+ department_id: 1
8
+ location_id: 1
9
+
@@ -0,0 +1,3 @@
1
+ class Group < ActiveRecord::Base
2
+ has_many :memberships
3
+ end
@@ -0,0 +1,3 @@
1
+ cpk:
2
+ id: 1
3
+ name: Composite Primary Keys
@@ -0,0 +1,6 @@
1
+ class Hack < ActiveRecord::Base
2
+ set_primary_keys :name
3
+ has_many :comments, :as => :person
4
+
5
+ has_one :first_comment, :as => :person, :class_name => "Comment"
6
+ end
@@ -0,0 +1,2 @@
1
+ andrew:
2
+ name: andrew
@@ -0,0 +1,3 @@
1
+ class KitchenSink < ActiveRecord::Base
2
+ set_primary_keys :id_1, :id_2
3
+ end
@@ -0,0 +1,5 @@
1
+ first:
2
+ id_1: 1
3
+ id_2: 2
4
+ a_date: <%= Date.today.to_s(:db) %>
5
+ a_string: 'string'
@@ -0,0 +1,10 @@
1
+ class Membership < ActiveRecord::Base
2
+ # set_primary_keys *keys - turns on composite key functionality
3
+ set_primary_keys :user_id, :group_id
4
+ belongs_to :user
5
+ belongs_to :group
6
+ has_many :statuses, :class_name => 'MembershipStatus', :foreign_key => [:user_id, :group_id]
7
+
8
+ has_many :readings, :primary_key => :user_id, :foreign_key => :user_id
9
+ has_one :reading, :primary_key => :user_id, :foreign_key => :user_id, :order => 'id DESC'
10
+ end
@@ -0,0 +1,3 @@
1
+ class MembershipStatus < ActiveRecord::Base
2
+ belongs_to :membership, :foreign_key => [:user_id, :group_id]
3
+ end
@@ -0,0 +1,10 @@
1
+ santiago-cpk:
2
+ id: 1
3
+ user_id: 1
4
+ group_id: 1
5
+ status: Active
6
+ drnic-cpk:
7
+ id: 2
8
+ user_id: 2
9
+ group_id: 1
10
+ status: Owner
@@ -0,0 +1,6 @@
1
+ santiago-cpk:
2
+ user_id: 1
3
+ group_id: 1
4
+ drnic-cpk:
5
+ user_id: 2
6
+ group_id: 1
@@ -0,0 +1,7 @@
1
+ class Product < ActiveRecord::Base
2
+ set_primary_keys :id # redundant
3
+ has_many :product_tariffs, :foreign_key => :product_id
4
+ has_one :product_tariff, :foreign_key => :product_id
5
+
6
+ has_many :tariffs, :through => :product_tariffs, :foreign_key => [:tariff_id, :tariff_start_date]
7
+ end
@@ -0,0 +1,5 @@
1
+ class ProductTariff < ActiveRecord::Base
2
+ set_primary_keys :product_id, :tariff_id, :tariff_start_date
3
+ belongs_to :product, :foreign_key => :product_id
4
+ belongs_to :tariff, :foreign_key => [:tariff_id, :tariff_start_date]
5
+ end
@@ -0,0 +1,12 @@
1
+ first_flat:
2
+ product_id: 1
3
+ tariff_id: 1
4
+ tariff_start_date: <%= Date.today.to_s(:db) %>
5
+ first_free:
6
+ product_id: 1
7
+ tariff_id: 2
8
+ tariff_start_date: <%= Date.today.to_s(:db) %>
9
+ second_free:
10
+ product_id: 2
11
+ tariff_id: 2
12
+ tariff_start_date: <%= Date.today.to_s(:db) %>
@@ -0,0 +1,6 @@
1
+ first_product:
2
+ id: 1
3
+ name: Product One
4
+ second_product:
5
+ id: 2
6
+ name: Product Two
@@ -0,0 +1,4 @@
1
+ class Reading < ActiveRecord::Base
2
+ belongs_to :article
3
+ belongs_to :user
4
+ end
@@ -0,0 +1,10 @@
1
+ santiago_first:
2
+ id: 1
3
+ user_id: 1
4
+ article_id: 1
5
+ rating: 4
6
+ santiago_second:
7
+ id: 2
8
+ user_id: 1
9
+ article_id: 2
10
+ rating: 5
@@ -0,0 +1,7 @@
1
+ class ReferenceCode < ActiveRecord::Base
2
+ set_primary_keys :reference_type_id, :reference_code
3
+
4
+ belongs_to :reference_type, :foreign_key => "reference_type_id"
5
+
6
+ validates_presence_of :reference_code, :code_label, :abbreviation
7
+ end
@@ -0,0 +1,28 @@
1
+ name_prefix_mr:
2
+ reference_type_id: 1
3
+ reference_code: 1
4
+ code_label: MR
5
+ abbreviation: Mr
6
+ name_prefix_mrs:
7
+ reference_type_id: 1
8
+ reference_code: 2
9
+ code_label: MRS
10
+ abbreviation: Mrs
11
+ name_prefix_ms:
12
+ reference_type_id: 1
13
+ reference_code: 3
14
+ code_label: MS
15
+ abbreviation: Ms
16
+
17
+ gender_male:
18
+ reference_type_id: 2
19
+ reference_code: 1
20
+ code_label: MALE
21
+ abbreviation: Male
22
+ gender_female:
23
+ reference_type_id: 2
24
+ reference_code: 2
25
+ code_label: FEMALE
26
+ abbreviation: Female
27
+
28
+
@@ -0,0 +1,7 @@
1
+ class ReferenceType < ActiveRecord::Base
2
+ set_primary_key :reference_type_id
3
+ has_many :reference_codes, :foreign_key => "reference_type_id"
4
+
5
+ validates_presence_of :type_label, :abbreviation
6
+ validates_uniqueness_of :type_label
7
+ end
@@ -0,0 +1,9 @@
1
+ name_prefix:
2
+ reference_type_id: 1
3
+ type_label: NAME_PREFIX
4
+ abbreviation: Name Prefix
5
+
6
+ gender:
7
+ reference_type_id: 2
8
+ type_label: GENDER
9
+ abbreviation: Gender
@@ -0,0 +1,6 @@
1
+ class Restaurant < ActiveRecord::Base
2
+ set_primary_keys :franchise_id, :store_id
3
+ has_and_belongs_to_many :suburbs,
4
+ :foreign_key => [:franchise_id, :store_id],
5
+ :association_foreign_key => [:city_id, :suburb_id]
6
+ end
@@ -0,0 +1,5 @@
1
+ mcdonalds:
2
+ franchise_id: 1
3
+ store_id: 1
4
+ name: McDonalds
5
+
@@ -0,0 +1,11 @@
1
+ a:
2
+ franchise_id: 1
3
+ store_id: 1
4
+ city_id: 1
5
+ suburb_id: 1
6
+
7
+ b:
8
+ franchise_id: 1
9
+ store_id: 1
10
+ city_id: 2
11
+ suburb_id: 1
@@ -0,0 +1,10 @@
1
+ class Room < ActiveRecord::Base
2
+ set_primary_keys :dorm_id, :room_id
3
+ belongs_to :dorm
4
+ has_many :room_attribute_assignments, :foreign_key => [:dorm_id, :room_id]
5
+ has_many :room_attributes, :through => :room_attribute_assignments
6
+
7
+ def find_custom_room_attributes
8
+ room_attributes.find(:all, :conditions => ["room_attributes.name != ?", "keg"])
9
+ end
10
+ end
@@ -0,0 +1,4 @@
1
+ class RoomAssignment < ActiveRecord::Base
2
+ belongs_to :student
3
+ belongs_to :room, :foreign_key => [:dorm_id, :room_id]
4
+ end
@@ -0,0 +1,4 @@
1
+ jacksons_room:
2
+ student_id: 1
3
+ dorm_id: 1
4
+ room_id: 1