globe-composite_primary_keys 3.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/History.txt +203 -0
- data/Manifest.txt +121 -0
- data/README.txt +41 -0
- data/README_DB2.txt +33 -0
- data/Rakefile +30 -0
- data/composite_primary_keys.gemspec +17 -0
- data/lib/adapter_helper/base.rb +63 -0
- data/lib/adapter_helper/mysql.rb +13 -0
- data/lib/adapter_helper/oracle.rb +12 -0
- data/lib/adapter_helper/oracle_enhanced.rb +12 -0
- data/lib/adapter_helper/postgresql.rb +13 -0
- data/lib/adapter_helper/sqlite3.rb +13 -0
- data/lib/composite_primary_keys.rb +63 -0
- data/lib/composite_primary_keys/association_preload.rb +162 -0
- data/lib/composite_primary_keys/associations.rb +159 -0
- data/lib/composite_primary_keys/attribute_methods.rb +84 -0
- data/lib/composite_primary_keys/base.rb +200 -0
- data/lib/composite_primary_keys/composite_arrays.rb +29 -0
- data/lib/composite_primary_keys/connection_adapters/abstract_adapter.rb +9 -0
- data/lib/composite_primary_keys/connection_adapters/ibm_db_adapter.rb +21 -0
- data/lib/composite_primary_keys/connection_adapters/oracle_adapter.rb +15 -0
- data/lib/composite_primary_keys/connection_adapters/oracle_enhanced_adapter.rb +17 -0
- data/lib/composite_primary_keys/connection_adapters/postgresql_adapter.rb +53 -0
- data/lib/composite_primary_keys/connection_adapters/sqlite3_adapter.rb +15 -0
- data/lib/composite_primary_keys/finder_methods.rb +68 -0
- data/lib/composite_primary_keys/fixtures.rb +8 -0
- data/lib/composite_primary_keys/read.rb +25 -0
- data/lib/composite_primary_keys/reflection.rb +39 -0
- data/lib/composite_primary_keys/relation.rb +31 -0
- data/lib/composite_primary_keys/through_association_scope.rb +212 -0
- data/lib/composite_primary_keys/validations/uniqueness.rb +118 -0
- data/lib/composite_primary_keys/version.rb +9 -0
- data/loader.rb +24 -0
- data/local/database_connections.rb.sample +12 -0
- data/local/paths.rb.sample +2 -0
- data/local/tasks.rb.sample +2 -0
- data/scripts/console.rb +48 -0
- data/scripts/txt2html +67 -0
- data/scripts/txt2js +59 -0
- data/tasks/activerecord_selection.rake +43 -0
- data/tasks/databases.rake +12 -0
- data/tasks/databases/mysql.rake +30 -0
- data/tasks/databases/oracle.rake +25 -0
- data/tasks/databases/postgresql.rake +25 -0
- data/tasks/databases/sqlite3.rake +28 -0
- data/tasks/deployment.rake +22 -0
- data/tasks/local_setup.rake +13 -0
- data/tasks/website.rake +18 -0
- data/test/README_tests.txt +67 -0
- data/test/abstract_unit.rb +103 -0
- data/test/connections/native_ibm_db/connection.rb +23 -0
- data/test/connections/native_mysql/connection.rb +13 -0
- data/test/connections/native_oracle/connection.rb +14 -0
- data/test/connections/native_oracle_enhanced/connection.rb +20 -0
- data/test/connections/native_postgresql/connection.rb +8 -0
- data/test/connections/native_sqlite/connection.rb +9 -0
- data/test/fixtures/article.rb +5 -0
- data/test/fixtures/article_group.rb +4 -0
- data/test/fixtures/article_groups.yml +7 -0
- data/test/fixtures/articles.yml +6 -0
- data/test/fixtures/comment.rb +6 -0
- data/test/fixtures/comments.yml +16 -0
- data/test/fixtures/db_definitions/db2-create-tables.sql +113 -0
- data/test/fixtures/db_definitions/db2-drop-tables.sql +16 -0
- data/test/fixtures/db_definitions/mysql.sql +181 -0
- data/test/fixtures/db_definitions/oracle.drop.sql +39 -0
- data/test/fixtures/db_definitions/oracle.sql +188 -0
- data/test/fixtures/db_definitions/postgresql.sql +206 -0
- data/test/fixtures/db_definitions/sqlite.sql +166 -0
- data/test/fixtures/department.rb +5 -0
- data/test/fixtures/departments.yml +3 -0
- data/test/fixtures/dorm.rb +3 -0
- data/test/fixtures/dorms.yml +2 -0
- data/test/fixtures/employee.rb +4 -0
- data/test/fixtures/employees.yml +9 -0
- data/test/fixtures/group.rb +3 -0
- data/test/fixtures/groups.yml +3 -0
- data/test/fixtures/hack.rb +6 -0
- data/test/fixtures/hacks.yml +2 -0
- data/test/fixtures/kitchen_sink.rb +3 -0
- data/test/fixtures/kitchen_sinks.yml +5 -0
- data/test/fixtures/membership.rb +10 -0
- data/test/fixtures/membership_status.rb +3 -0
- data/test/fixtures/membership_statuses.yml +10 -0
- data/test/fixtures/memberships.yml +6 -0
- data/test/fixtures/product.rb +7 -0
- data/test/fixtures/product_tariff.rb +5 -0
- data/test/fixtures/product_tariffs.yml +12 -0
- data/test/fixtures/products.yml +6 -0
- data/test/fixtures/reading.rb +4 -0
- data/test/fixtures/readings.yml +10 -0
- data/test/fixtures/reference_code.rb +7 -0
- data/test/fixtures/reference_codes.yml +28 -0
- data/test/fixtures/reference_type.rb +7 -0
- data/test/fixtures/reference_types.yml +9 -0
- data/test/fixtures/restaurant.rb +6 -0
- data/test/fixtures/restaurants.yml +5 -0
- data/test/fixtures/restaurants_suburbs.yml +11 -0
- data/test/fixtures/room.rb +10 -0
- data/test/fixtures/room_assignment.rb +4 -0
- data/test/fixtures/room_assignments.yml +4 -0
- data/test/fixtures/room_attribute.rb +3 -0
- data/test/fixtures/room_attribute_assignment.rb +5 -0
- data/test/fixtures/room_attribute_assignments.yml +4 -0
- data/test/fixtures/room_attributes.yml +3 -0
- data/test/fixtures/rooms.yml +3 -0
- data/test/fixtures/seat.rb +5 -0
- data/test/fixtures/seats.yml +4 -0
- data/test/fixtures/street.rb +3 -0
- data/test/fixtures/streets.yml +15 -0
- data/test/fixtures/student.rb +4 -0
- data/test/fixtures/students.yml +2 -0
- data/test/fixtures/suburb.rb +6 -0
- data/test/fixtures/suburbs.yml +9 -0
- data/test/fixtures/tariff.rb +6 -0
- data/test/fixtures/tariffs.yml +13 -0
- data/test/fixtures/user.rb +10 -0
- data/test/fixtures/users.yml +6 -0
- data/test/hash_tricks.rb +34 -0
- data/test/plugins/pagination.rb +405 -0
- data/test/plugins/pagination_helper.rb +135 -0
- data/test/test_associations.rb +178 -0
- data/test/test_attribute_methods.rb +22 -0
- data/test/test_attributes.rb +80 -0
- data/test/test_clone.rb +34 -0
- data/test/test_composite_arrays.rb +32 -0
- data/test/test_create.rb +68 -0
- data/test/test_delete.rb +83 -0
- data/test/test_exists.rb +25 -0
- data/test/test_find.rb +73 -0
- data/test/test_ids.rb +90 -0
- data/test/test_miscellaneous.rb +39 -0
- data/test/test_pagination.rb +38 -0
- data/test/test_polymorphic.rb +32 -0
- data/test/test_santiago.rb +27 -0
- data/test/test_suite.rb +19 -0
- data/test/test_tutorial_example.rb +26 -0
- data/test/test_update.rb +40 -0
- data/test/test_validations.rb +11 -0
- data/website/index.html +195 -0
- data/website/index.txt +159 -0
- data/website/javascripts/rounded_corners_lite.inc.js +285 -0
- data/website/stylesheets/screen.css +126 -0
- data/website/template.js +3 -0
- data/website/template.rhtml +53 -0
- data/website/version-raw.js +3 -0
- data/website/version-raw.txt +2 -0
- data/website/version.js +4 -0
- data/website/version.txt +3 -0
- 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,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,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,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,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,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
|