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.
Files changed (36) hide show
  1. checksums.yaml +4 -4
  2. data/History.rdoc +6 -0
  3. data/Rakefile +1 -1
  4. data/lib/composite_primary_keys/associations/association.rb +2 -2
  5. data/lib/composite_primary_keys/associations/association_scope.rb +1 -1
  6. data/lib/composite_primary_keys/associations/has_many_through_association.rb +19 -0
  7. data/lib/composite_primary_keys/connection_adapters/abstract/database_statements.rb +1 -2
  8. data/lib/composite_primary_keys/relation/query_methods.rb +14 -16
  9. data/lib/composite_primary_keys/relation.rb +199 -197
  10. data/lib/composite_primary_keys/version.rb +1 -1
  11. data/lib/composite_primary_keys.rb +117 -119
  12. data/scripts/console.rb +2 -2
  13. data/tasks/databases/trilogy.rake +23 -0
  14. data/test/abstract_unit.rb +124 -118
  15. data/test/connections/databases.ci.yml +10 -0
  16. data/test/fixtures/admin.rb +4 -0
  17. data/test/fixtures/comments.yml +6 -0
  18. data/test/fixtures/db_definitions/db2-create-tables.sql +34 -0
  19. data/test/fixtures/db_definitions/db2-drop-tables.sql +7 -1
  20. data/test/fixtures/db_definitions/mysql.sql +23 -0
  21. data/test/fixtures/db_definitions/oracle.drop.sql +4 -0
  22. data/test/fixtures/db_definitions/oracle.sql +21 -0
  23. data/test/fixtures/db_definitions/postgresql.sql +23 -0
  24. data/test/fixtures/db_definitions/sqlite.sql +21 -0
  25. data/test/fixtures/db_definitions/sqlserver.sql +23 -0
  26. data/test/fixtures/moderator.rb +4 -0
  27. data/test/fixtures/room.rb +4 -1
  28. data/test/fixtures/staff_room.rb +6 -0
  29. data/test/fixtures/staff_room_key.rb +6 -0
  30. data/test/fixtures/user.rb +3 -0
  31. data/test/fixtures/user_with_polymorphic_name.rb +9 -0
  32. data/test/test_associations.rb +403 -403
  33. data/test/test_has_one_through.rb +30 -0
  34. data/test/test_polymorphic.rb +6 -0
  35. metadata +11 -4
  36. 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
  );
@@ -0,0 +1,4 @@
1
+ class Moderator < ActiveRecord::Base
2
+ belongs_to :user, :foreign_key => :id, :inverse_of => :moderator
3
+ has_one :admin, :foreign_key => :id, :inverse_of => :moderator
4
+ end
@@ -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
@@ -0,0 +1,6 @@
1
+ class StaffRoom < ActiveRecord::Base
2
+ self.primary_keys = :dorm_id, :room_id
3
+
4
+ belongs_to :room, :foreign_key => [:dorm_id, :room_id], :inverse_of => :staff_room
5
+ has_one :staff_room_key, :foreign_key => [:dorm_id, :room_id], :inverse_of => :staff_room
6
+ end
@@ -0,0 +1,6 @@
1
+ class StaffRoomKey < ActiveRecord::Base
2
+ self.primary_keys = :dorm_id, :room_id
3
+
4
+ belongs_to :staff_room, :foreign_key => [:dorm_id, :room_id], :inverse_of => :staff_room_key
5
+ has_one :room, :through => :staff_room
6
+ end
@@ -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
@@ -0,0 +1,9 @@
1
+ class UserWithPolymorphicName < ActiveRecord::Base
2
+ self.table_name = "users"
3
+
4
+ has_many :comments, :as => :person
5
+
6
+ def self.polymorphic_name
7
+ "User1"
8
+ end
9
+ end