composite_primary_keys 14.0.6 → 14.0.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/History.rdoc +6 -0
- data/Rakefile +1 -1
- data/lib/composite_primary_keys/associations/association.rb +2 -2
- data/lib/composite_primary_keys/associations/association_scope.rb +1 -1
- data/lib/composite_primary_keys/associations/has_many_through_association.rb +19 -0
- data/lib/composite_primary_keys/connection_adapters/abstract/database_statements.rb +1 -2
- data/lib/composite_primary_keys/relation/query_methods.rb +14 -16
- data/lib/composite_primary_keys/relation.rb +199 -197
- data/lib/composite_primary_keys/version.rb +1 -1
- data/lib/composite_primary_keys.rb +117 -119
- data/scripts/console.rb +2 -2
- data/tasks/databases/trilogy.rake +23 -0
- data/test/abstract_unit.rb +124 -118
- data/test/connections/databases.ci.yml +10 -0
- data/test/fixtures/admin.rb +4 -0
- data/test/fixtures/comments.yml +6 -0
- data/test/fixtures/db_definitions/db2-create-tables.sql +34 -0
- data/test/fixtures/db_definitions/db2-drop-tables.sql +7 -1
- data/test/fixtures/db_definitions/mysql.sql +23 -0
- data/test/fixtures/db_definitions/oracle.drop.sql +4 -0
- data/test/fixtures/db_definitions/oracle.sql +21 -0
- data/test/fixtures/db_definitions/postgresql.sql +23 -0
- data/test/fixtures/db_definitions/sqlite.sql +21 -0
- data/test/fixtures/db_definitions/sqlserver.sql +23 -0
- data/test/fixtures/moderator.rb +4 -0
- data/test/fixtures/room.rb +4 -1
- data/test/fixtures/staff_room.rb +6 -0
- data/test/fixtures/staff_room_key.rb +6 -0
- data/test/fixtures/user.rb +3 -0
- data/test/fixtures/user_with_polymorphic_name.rb +9 -0
- data/test/test_associations.rb +403 -403
- data/test/test_has_one_through.rb +30 -0
- data/test/test_polymorphic.rb +6 -0
- metadata +11 -4
- data/lib/composite_primary_keys/associations/through_association.rb +0 -24
@@ -58,6 +58,16 @@ create table users (
|
|
58
58
|
primary key (id)
|
59
59
|
);
|
60
60
|
|
61
|
+
create table moderators (
|
62
|
+
id int not null,
|
63
|
+
primary key (id)
|
64
|
+
);
|
65
|
+
|
66
|
+
create table admins (
|
67
|
+
id int not null,
|
68
|
+
primary key (id)
|
69
|
+
);
|
70
|
+
|
61
71
|
create table articles (
|
62
72
|
id int not null auto_increment,
|
63
73
|
name varchar(50) not null,
|
@@ -152,6 +162,19 @@ create table room_attribute_assignments (
|
|
152
162
|
room_attribute_id int not null
|
153
163
|
);
|
154
164
|
|
165
|
+
create table staff_rooms (
|
166
|
+
dorm_id int not null,
|
167
|
+
room_id int not null,
|
168
|
+
primary key (dorm_id, room_id)
|
169
|
+
);
|
170
|
+
|
171
|
+
create table staff_room_keys (
|
172
|
+
dorm_id int not null,
|
173
|
+
room_id int not null,
|
174
|
+
key_no varchar(50) not null,
|
175
|
+
primary key (dorm_id, room_id)
|
176
|
+
);
|
177
|
+
|
155
178
|
create table students (
|
156
179
|
id int not null auto_increment,
|
157
180
|
primary key(id)
|
@@ -11,6 +11,8 @@ drop table streets;
|
|
11
11
|
drop sequence streets_seq;
|
12
12
|
drop table users;
|
13
13
|
drop sequence users_seq;
|
14
|
+
drop table moderators;
|
15
|
+
drop table admins;
|
14
16
|
drop table articles;
|
15
17
|
drop sequence articles_seq;
|
16
18
|
drop table readings;
|
@@ -35,6 +37,8 @@ drop table room_attributes;
|
|
35
37
|
drop sequence room_attributes_seq;
|
36
38
|
drop table room_attribute_assignments;
|
37
39
|
drop table room_assignments;
|
40
|
+
drop table staff_rooms;
|
41
|
+
drop table staff_room_keys;
|
38
42
|
drop table students;
|
39
43
|
drop sequence students_seq;
|
40
44
|
drop table capitols;
|
@@ -63,6 +63,14 @@ create table users (
|
|
63
63
|
name varchar(50) not null
|
64
64
|
);
|
65
65
|
|
66
|
+
create table moderators (
|
67
|
+
id number(11) primary key
|
68
|
+
);
|
69
|
+
|
70
|
+
create table admins (
|
71
|
+
id number(11) primary key
|
72
|
+
);
|
73
|
+
|
66
74
|
create sequence articles_seq start with 1000;
|
67
75
|
|
68
76
|
create table articles (
|
@@ -169,6 +177,19 @@ create table room_attribute_assignments (
|
|
169
177
|
room_attribute_id number(11) not null
|
170
178
|
);
|
171
179
|
|
180
|
+
create table staff_rooms (
|
181
|
+
dorm_id number(11) not null,
|
182
|
+
room_id number(11) not null,
|
183
|
+
constraint staff_rooms_pk primary key (dorm_id, room_id)
|
184
|
+
);
|
185
|
+
|
186
|
+
create table staff_room_keys (
|
187
|
+
dorm_id number(11) not null,
|
188
|
+
room_id number(11) not null,
|
189
|
+
key_no varchar(50) not null,
|
190
|
+
constraint staff_room_keys_pk primary key (dorm_id, room_id)
|
191
|
+
);
|
192
|
+
|
172
193
|
create sequence students_seq start with 1000;
|
173
194
|
|
174
195
|
create table students (
|
@@ -60,6 +60,16 @@ create table users (
|
|
60
60
|
primary key (id)
|
61
61
|
);
|
62
62
|
|
63
|
+
create table moderators (
|
64
|
+
id serial not null,
|
65
|
+
primary key (id)
|
66
|
+
);
|
67
|
+
|
68
|
+
create table admins (
|
69
|
+
id serial not null,
|
70
|
+
primary key (id)
|
71
|
+
);
|
72
|
+
|
63
73
|
create table articles (
|
64
74
|
id serial not null,
|
65
75
|
name varchar(50) not null,
|
@@ -154,6 +164,19 @@ create table room_attribute_assignments (
|
|
154
164
|
room_attribute_id int not null
|
155
165
|
);
|
156
166
|
|
167
|
+
create table staff_rooms (
|
168
|
+
dorm_id int not null,
|
169
|
+
room_id int not null,
|
170
|
+
primary key (dorm_id, room_id)
|
171
|
+
);
|
172
|
+
|
173
|
+
create table staff_room_keys (
|
174
|
+
dorm_id int not null,
|
175
|
+
room_id int not null,
|
176
|
+
key_no varchar(50) not null,
|
177
|
+
primary key (dorm_id, room_id)
|
178
|
+
);
|
179
|
+
|
157
180
|
create table students (
|
158
181
|
id serial not null,
|
159
182
|
primary key (id)
|
@@ -56,6 +56,14 @@ create table users (
|
|
56
56
|
name varchar(50) not null
|
57
57
|
);
|
58
58
|
|
59
|
+
create table moderators (
|
60
|
+
id integer not null primary key
|
61
|
+
);
|
62
|
+
|
63
|
+
create table admins (
|
64
|
+
id integer not null primary key
|
65
|
+
);
|
66
|
+
|
59
67
|
create table articles (
|
60
68
|
id integer not null primary key autoincrement,
|
61
69
|
name varchar(50) not null
|
@@ -142,6 +150,19 @@ create table room_attribute_assignments (
|
|
142
150
|
room_attribute_id integer not null
|
143
151
|
);
|
144
152
|
|
153
|
+
create table staff_rooms (
|
154
|
+
dorm_id integer not null,
|
155
|
+
room_id integer not null,
|
156
|
+
primary key (dorm_id, room_id)
|
157
|
+
);
|
158
|
+
|
159
|
+
create table staff_room_keys (
|
160
|
+
dorm_id integer not null,
|
161
|
+
room_id integer not null,
|
162
|
+
key_no varchar(50) not null,
|
163
|
+
primary key (dorm_id, room_id)
|
164
|
+
);
|
165
|
+
|
145
166
|
create table students (
|
146
167
|
id integer not null primary key autoincrement
|
147
168
|
);
|
@@ -58,6 +58,14 @@ CREATE TABLE users (
|
|
58
58
|
name varchar(50) NOT NULL
|
59
59
|
);
|
60
60
|
|
61
|
+
CREATE TABLE moderators (
|
62
|
+
id [int] PRIMARY KEY
|
63
|
+
);
|
64
|
+
|
65
|
+
CREATE TABLE admins (
|
66
|
+
id [int] PRIMARY KEY
|
67
|
+
);
|
68
|
+
|
61
69
|
CREATE TABLE articles (
|
62
70
|
id [int] IDENTITY(1000,1) NOT NULL,
|
63
71
|
name varchar(50) NOT NULL
|
@@ -148,6 +156,21 @@ CREATE TABLE room_attribute_assignments (
|
|
148
156
|
room_attribute_id [int] NOT NULL
|
149
157
|
);
|
150
158
|
|
159
|
+
CREATE TABLE staff_rooms (
|
160
|
+
dorm_id [int] NOT NULL,
|
161
|
+
room_id [int] NOT NULL,
|
162
|
+
CONSTRAINT [staff_rooms_pk] PRIMARY KEY CLUSTERED
|
163
|
+
( [dorm_id], [room_id] )
|
164
|
+
);
|
165
|
+
|
166
|
+
CREATE TABLE staff_room_keys (
|
167
|
+
dorm_id [int] NOT NULL,
|
168
|
+
room_id [int] NOT NULL,
|
169
|
+
key_no [varchar](50) NOT NULL,
|
170
|
+
CONSTRAINT [staff_room_keys_pk] PRIMARY KEY CLUSTERED
|
171
|
+
( [dorm_id], [room_id] )
|
172
|
+
);
|
173
|
+
|
151
174
|
CREATE TABLE students (
|
152
175
|
id [int] IDENTITY(1000,1) PRIMARY KEY NOT NULL
|
153
176
|
);
|
data/test/fixtures/room.rb
CHANGED
@@ -4,7 +4,10 @@ class Room < ActiveRecord::Base
|
|
4
4
|
has_many :room_assignments, :foreign_key => [:dorm_id, :room_id]
|
5
5
|
has_many :room_attribute_assignments, :foreign_key => [:dorm_id, :room_id]
|
6
6
|
has_many :room_attributes, :through => :room_attribute_assignments
|
7
|
-
|
7
|
+
|
8
|
+
has_one :staff_room, :foreign_key => [:dorm_id, :room_id], :inverse_of => :room
|
9
|
+
delegate :staff_room_key, :to => :staff_room, :allow_nil => true
|
10
|
+
|
8
11
|
def find_custom_room_attributes
|
9
12
|
room_attributes.where("room_attributes.name != ?", "type")
|
10
13
|
end
|
data/test/fixtures/user.rb
CHANGED
@@ -5,6 +5,9 @@ class User < ActiveRecord::Base
|
|
5
5
|
has_many :comments, :as => :person
|
6
6
|
has_one :first_comment, :as => :person, :class_name => "Comment"
|
7
7
|
|
8
|
+
has_one :moderator, :foreign_key => :id, :inverse_of => :user
|
9
|
+
delegate :admin, :to => :moderator, :allow_nil => true
|
10
|
+
|
8
11
|
def find_custom_articles
|
9
12
|
articles.where("name = ?", "Article One")
|
10
13
|
end
|