composite_primary_keys 3.0.0.b2 → 3.0.0.b3

Sign up to get free protection for your applications and to get access to all the features.
@@ -95,19 +95,20 @@ module ActiveRecord
95
95
  [id_rel, type_rel]
96
96
  else
97
97
  foreign_key = options[:foreign_key] || reflection.active_record.name.foreign_key
98
+
98
99
  # CPK
99
- # [aliased_table[foreign_key].eq(parent_table[reflection.options[:primary_key] || parent.primary_key])]
100
+ #[aliased_table[foreign_key].eq(parent_table[reflection.options[:primary_key] || parent.primary_key])]
100
101
  composite_join_predicates(aliased_table, foreign_key,
101
102
  parent_table, reflection.options[:primary_key] || parent.primary_key)
102
103
  end
103
104
  when :belongs_to
104
- [aliased_table[options[:primary_key] || reflection.klass.primary_key].eq(parent_table[options[:foreign_key] || reflection.cpk_primary_key])]
105
+ [aliased_table[options[:primary_key] || reflection.klass.primary_key].eq(parent_table[options[:foreign_key] || reflection.primary_key_name])]
105
106
  end
106
107
 
107
108
  unless klass.descends_from_active_record?
108
109
  sti_column = aliased_table[klass.inheritance_column]
109
110
  sti_condition = sti_column.eq(klass.sti_name)
110
- klass.send(:subclasses).each {|subclass| sti_condition = sti_condition.or(sti_column.eq(subclass.sti_name)) }
111
+ klass.descendants.each {|subclass| sti_condition = sti_condition.or(sti_column.eq(subclass.sti_name)) }
111
112
 
112
113
  @join << sti_condition
113
114
  end
@@ -2,6 +2,35 @@ module CompositePrimaryKeys
2
2
  module ActiveRecord
3
3
  module FinderMethods
4
4
  module InstanceMethods
5
+ def construct_limited_ids_condition(relation)
6
+ orders = relation.order_values.join(", ")
7
+
8
+ # CPK
9
+ # values = @klass.connection.distinct("#{@klass.connection.quote_table_name @klass.table_name}.#{@klass.primary_key}", orders)
10
+
11
+ keys = @klass.primary_keys.map do |key|
12
+ "#{@klass.connection.quote_table_name @klass.table_name}.#{key}"
13
+ end
14
+ values = @klass.connection.distinct(keys.join(', '), orders)
15
+
16
+ ids_array = relation.select(values).collect {|row| row[@klass.primary_key]}
17
+
18
+ # CPK
19
+ # ids_array.empty? ? raise(ThrowResult) : primary_key.in(ids_array)
20
+
21
+ # OR together each and expression (key=value and key=value) that matches an id set
22
+ # since we only need to match 0 or more records
23
+ or_expressions = ids_array.map do |id_set|
24
+ # AND together "key=value" exprssios to match each id set
25
+ and_expressions = [self.primary_keys, id_set].transpose.map do |key, id|
26
+ table[key].eq(id)
27
+ end
28
+ Arel::Predicates::All.new(*and_expressions)
29
+ end
30
+
31
+ Arel::Predicates::Any.new(*or_expressions).to_sql
32
+ end
33
+
5
34
  def exists?(id = nil)
6
35
  case id
7
36
  when Array
@@ -0,0 +1,24 @@
1
+ module ActiveRecord
2
+ module QueryMethods
3
+ def reverse_order
4
+ order_clause = arel.order_clauses.join(', ')
5
+ relation = except(:order)
6
+
7
+ # CPK
8
+ # order = order_clause.blank? ?
9
+ # "#{@klass.table_name}.#{@klass.primary_key} DESC" :
10
+ # reverse_sql_order(order_clause)
11
+
12
+ order = unless order_clause.blank?
13
+ reverse_sql_order(order_clause)
14
+ else
15
+ primary_keys = composite? ? @klass.primary_keys : [@klass.primary_key]
16
+ primary_keys.map do |key|
17
+ "#{@klass.table_name}.#{key} DESC"
18
+ end.join(", ")
19
+ end
20
+
21
+ relation.order Arel::SqlLiteral.new order
22
+ end
23
+ end
24
+ end
@@ -3,7 +3,7 @@ module CompositePrimaryKeys
3
3
  MAJOR = 3
4
4
  MINOR = 0
5
5
  TINY = 0
6
- PATCH = 'b2'
6
+ PATCH = 'b3'
7
7
  STRING = [MAJOR, MINOR, TINY, PATCH].join('.')
8
8
  end
9
9
  end
@@ -44,6 +44,7 @@ require 'active_record/associations/has_many_association'
44
44
  require 'active_record/associations/has_one_association'
45
45
  require 'active_record/associations/has_one_through_association'
46
46
  require 'active_record/associations/through_association_scope'
47
+ require 'active_record/relation/query_methods'
47
48
 
48
49
  require 'composite_primary_keys/fixtures'
49
50
  require 'composite_primary_keys/composite_arrays'
@@ -61,6 +62,7 @@ require 'composite_primary_keys/finder_methods'
61
62
  require 'composite_primary_keys/base'
62
63
  require 'composite_primary_keys/calculations'
63
64
  require 'composite_primary_keys/validations/uniqueness'
65
+ require 'composite_primary_keys/query_methods'
64
66
 
65
67
  Dir[File.dirname(__FILE__) + '/composite_primary_keys/connection_adapters/*.rb'].each do |adapter|
66
68
  begin
@@ -11,7 +11,10 @@ require 'active_record'
11
11
  require 'active_record/fixtures'
12
12
  require File.join(PROJECT_ROOT, 'test', 'connections', 'connection_spec')
13
13
  require File.join(PROJECT_ROOT, "test", "connections", "native_#{adapter}", "connection")
14
- require 'composite_primary_keys'
14
+
15
+ # To make debugging easier, test within this source tree versus an installed gem
16
+ #require 'composite_primary_keys'
17
+ require File.join(PROJECT_ROOT, "lib", "composite_primary_keys")
15
18
 
16
19
  # Tell ActiveRecord where to find models
17
20
  ActiveSupport::Dependencies.autoload_paths << File.join(PROJECT_ROOT, 'test', 'fixtures')
data/test/debug.log ADDED
@@ -0,0 +1,276 @@
1
+ # Logfile created on Sat Nov 06 22:39:48 -0600 2010 by logger.rb/22285
2
+ SQL (0.0ms) SHOW client_min_messages
3
+ SQL (0.0ms) SET client_min_messages TO 'panic'
4
+ SQL (0.0ms) SET standard_conforming_strings = on
5
+ SQL (0.0ms) SET client_min_messages TO 'notice'
6
+ SQL (1.0ms) SHOW TIME ZONE
7
+ SQL (0.0ms) SHOW client_min_messages
8
+ SQL (1.0ms) SET client_min_messages TO 'panic'
9
+ SQL (0.0ms) SET standard_conforming_strings = on
10
+ SQL (0.0ms) SET client_min_messages TO 'notice'
11
+ SQL (0.0ms) SHOW TIME ZONE
12
+ PGError: ERROR: column suburbs.city_idsuburb_id does not exist
13
+ LINE 1: ...T "suburbs".* FROM "suburbs" ORDER BY suburbs.ci...
14
+ ^
15
+ : SELECT "suburbs".* FROM "suburbs" ORDER BY suburbs.city_idsuburb_id DESC LIMIT 1
16
+ SQL (0.0ms) SHOW client_min_messages
17
+ SQL (0.0ms) SET client_min_messages TO 'panic'
18
+ SQL (0.0ms) SET standard_conforming_strings = on
19
+ SQL (0.0ms) SET client_min_messages TO 'notice'
20
+ SQL (0.0ms) SHOW TIME ZONE
21
+ PGError: ERROR: column suburbs.city_idsuburb_id does not exist
22
+ LINE 1: ...T "suburbs".* FROM "suburbs" ORDER BY suburbs.ci...
23
+ ^
24
+ : SELECT "suburbs".* FROM "suburbs" ORDER BY suburbs.city_idsuburb_id DESC LIMIT 1
25
+ SQL (1.0ms) SHOW client_min_messages
26
+ SQL (0.0ms) SET client_min_messages TO 'panic'
27
+ SQL (0.0ms) SET standard_conforming_strings = on
28
+ SQL (0.0ms) SET client_min_messages TO 'notice'
29
+ SQL (0.0ms) SHOW TIME ZONE
30
+ PGError: ERROR: column suburbs.city_idsuburb_id does not exist
31
+ LINE 1: ...T "suburbs".* FROM "suburbs" ORDER BY suburbs.ci...
32
+ ^
33
+ : SELECT "suburbs".* FROM "suburbs" ORDER BY suburbs.city_idsuburb_id DESC LIMIT 1
34
+ SQL (0.0ms) SHOW client_min_messages
35
+ SQL (1.0ms) SET client_min_messages TO 'panic'
36
+ SQL (0.0ms) SET standard_conforming_strings = on
37
+ SQL (0.0ms) SET client_min_messages TO 'notice'
38
+ SQL (0.0ms) SHOW TIME ZONE
39
+ SQL (0.0ms) SHOW client_min_messages
40
+ SQL (0.0ms) SET client_min_messages TO 'panic'
41
+ SQL (0.0ms) SET standard_conforming_strings = on
42
+ SQL (0.0ms) SET client_min_messages TO 'notice'
43
+ SQL (0.0ms) SHOW TIME ZONE
44
+ SQL (0.0ms) SHOW client_min_messages
45
+ SQL (0.0ms) SET client_min_messages TO 'panic'
46
+ SQL (0.0ms) SET standard_conforming_strings = on
47
+ SQL (0.0ms) SET client_min_messages TO 'notice'
48
+ SQL (0.0ms) SHOW TIME ZONE
49
+ SQL (0.0ms) SHOW client_min_messages
50
+ SQL (0.0ms) SET client_min_messages TO 'panic'
51
+ SQL (0.0ms) SET standard_conforming_strings = on
52
+ SQL (0.0ms) SET client_min_messages TO 'notice'
53
+ SQL (0.0ms) SHOW TIME ZONE
54
+ PGError: ERROR: column suburbs.suburb_iddesc does not exist
55
+ LINE 1: ... FROM "suburbs" ORDER BY suburbs.city_id, suburbs.su...
56
+ ^
57
+ : SELECT "suburbs".* FROM "suburbs" ORDER BY suburbs.city_id, suburbs.suburb_idDESC LIMIT 1
58
+ SQL (0.0ms) SHOW client_min_messages
59
+ SQL (0.0ms) SET client_min_messages TO 'panic'
60
+ SQL (0.0ms) SET standard_conforming_strings = on
61
+ SQL (0.0ms) SET client_min_messages TO 'notice'
62
+ SQL (0.0ms) SHOW TIME ZONE
63
+ SQL (1.0ms) SHOW client_min_messages
64
+ SQL (0.0ms) SET client_min_messages TO 'panic'
65
+ SQL (0.0ms) SET standard_conforming_strings = on
66
+ SQL (0.0ms) SET client_min_messages TO 'notice'
67
+ SQL (1.0ms) SHOW TIME ZONE
68
+ SQL (0.0ms) SHOW client_min_messages
69
+ SQL (0.0ms) SET client_min_messages TO 'panic'
70
+ SQL (1.0ms) SET standard_conforming_strings = on
71
+ SQL (0.0ms) SET client_min_messages TO 'notice'
72
+ SQL (1.0ms) SHOW TIME ZONE
73
+ SQL (0.0ms) SHOW client_min_messages
74
+ SQL (1.0ms) SET client_min_messages TO 'panic'
75
+ SQL (0.0ms) SET standard_conforming_strings = on
76
+ SQL (0.0ms) SET client_min_messages TO 'notice'
77
+ SQL (0.0ms) SHOW TIME ZONE
78
+ SQL (0.0ms) SHOW client_min_messages
79
+ SQL (0.0ms) SET client_min_messages TO 'panic'
80
+ SQL (0.0ms) SET standard_conforming_strings = on
81
+ SQL (1.0ms) SET client_min_messages TO 'notice'
82
+ SQL (0.0ms) SHOW TIME ZONE
83
+ SQL (0.0ms) SHOW client_min_messages
84
+ SQL (0.0ms) SET client_min_messages TO 'panic'
85
+ SQL (1.0ms) SET standard_conforming_strings = on
86
+ SQL (0.0ms) SET client_min_messages TO 'notice'
87
+ SQL (0.0ms) SHOW TIME ZONE
88
+ SQL (0.0ms) SHOW client_min_messages
89
+ SQL (1.0ms) SET client_min_messages TO 'panic'
90
+ SQL (0.0ms) SET standard_conforming_strings = on
91
+ SQL (0.0ms) SET client_min_messages TO 'notice'
92
+ SQL (0.0ms) SHOW TIME ZONE
93
+ SQL (1.0ms) SHOW client_min_messages
94
+ SQL (1.0ms) SET client_min_messages TO 'panic'
95
+ SQL (0.0ms) SET standard_conforming_strings = on
96
+ SQL (0.0ms) SET client_min_messages TO 'notice'
97
+ SQL (0.0ms) SHOW TIME ZONE
98
+ SQL (0.0ms) SHOW client_min_messages
99
+ SQL (0.0ms) SET client_min_messages TO 'panic'
100
+ SQL (0.0ms) SET standard_conforming_strings = on
101
+ SQL (0.0ms) SET client_min_messages TO 'notice'
102
+ SQL (0.0ms) SHOW TIME ZONE
103
+ SQL (0.0ms) SHOW client_min_messages
104
+ SQL (0.0ms) SET client_min_messages TO 'panic'
105
+ SQL (0.0ms) SET standard_conforming_strings = on
106
+ SQL (0.0ms) SET client_min_messages TO 'notice'
107
+ SQL (1.0ms) SHOW TIME ZONE
108
+ SQL (0.0ms) SHOW client_min_messages
109
+ SQL (0.0ms) SET client_min_messages TO 'panic'
110
+ SQL (0.0ms) SET standard_conforming_strings = on
111
+ SQL (0.0ms) SET client_min_messages TO 'notice'
112
+ SQL (0.0ms) SHOW TIME ZONE
113
+ SQL (1.0ms) SHOW client_min_messages
114
+ SQL (0.0ms) SET client_min_messages TO 'panic'
115
+ SQL (0.0ms) SET standard_conforming_strings = on
116
+ SQL (1.0ms) SET client_min_messages TO 'notice'
117
+ SQL (0.0ms) SHOW TIME ZONE
118
+ SQL (1.0ms) SHOW client_min_messages
119
+ SQL (0.0ms) SET client_min_messages TO 'panic'
120
+ SQL (1.0ms) SET standard_conforming_strings = on
121
+ SQL (0.0ms) SET client_min_messages TO 'notice'
122
+ SQL (0.0ms) SHOW TIME ZONE
123
+ SQL (0.0ms) SHOW client_min_messages
124
+ SQL (0.0ms) SET client_min_messages TO 'panic'
125
+ SQL (0.0ms) SET standard_conforming_strings = on
126
+ SQL (0.0ms) SET client_min_messages TO 'notice'
127
+ SQL (1.0ms) SHOW TIME ZONE
128
+ PGError: ERROR: column memberships.user_idgroup_id does not exist
129
+ LINE 1: SELECT "memberships"."user_idgroup_id" AS t0_r0, "member...
130
+ ^
131
+ : SELECT "memberships"."user_idgroup_id" AS t0_r0, "memberships"."user_id" AS t0_r1, "memberships"."group_id" AS t0_r2, "membership_statuses"."id" AS t1_r0, "membership_statuses"."user_id" AS t1_r1, "membership_statuses"."group_id" AS t1_r2, "membership_statuses"."status" AS t1_r3 FROM "memberships" LEFT OUTER JOIN "membership_statuses" ON "membership_statuses"."user_id" = "memberships"."user_id" AND "membership_statuses"."group_id" = "memberships"."group_id" WHERE (membership_statuses.status = 'Active')
132
+ SQL (0.0ms) SHOW client_min_messages
133
+ SQL (0.0ms) SET client_min_messages TO 'panic'
134
+ SQL (0.0ms) SET standard_conforming_strings = on
135
+ SQL (1.0ms) SET client_min_messages TO 'notice'
136
+ SQL (0.0ms) SHOW TIME ZONE
137
+ SQL (0.0ms) SHOW client_min_messages
138
+ SQL (0.0ms) SET client_min_messages TO 'panic'
139
+ SQL (0.0ms) SET standard_conforming_strings = on
140
+ SQL (1.0ms) SET client_min_messages TO 'notice'
141
+ SQL (0.0ms) SHOW TIME ZONE
142
+ SQL (0.0ms) SHOW client_min_messages
143
+ SQL (0.0ms) SET client_min_messages TO 'panic'
144
+ SQL (0.0ms) SET standard_conforming_strings = on
145
+ SQL (0.0ms) SET client_min_messages TO 'notice'
146
+ SQL (0.0ms) SHOW TIME ZONE
147
+ SQL (0.0ms) SHOW client_min_messages
148
+ SQL (0.0ms) SET client_min_messages TO 'panic'
149
+ SQL (0.0ms) SET standard_conforming_strings = on
150
+ SQL (0.0ms) SET client_min_messages TO 'notice'
151
+ SQL (0.0ms) SHOW TIME ZONE
152
+ SQL (0.0ms) SHOW client_min_messages
153
+ SQL (0.0ms) SET client_min_messages TO 'panic'
154
+ SQL (0.0ms) SET standard_conforming_strings = on
155
+ SQL (0.0ms) SET client_min_messages TO 'notice'
156
+ SQL (0.0ms) SHOW TIME ZONE
157
+ SQL (0.0ms) SHOW client_min_messages
158
+ SQL (0.0ms) SET client_min_messages TO 'panic'
159
+ SQL (0.0ms) SET standard_conforming_strings = on
160
+ SQL (0.0ms) SET client_min_messages TO 'notice'
161
+ SQL (0.0ms) SHOW TIME ZONE
162
+ SQL (0.0ms) SHOW client_min_messages
163
+ SQL (0.0ms) SET client_min_messages TO 'panic'
164
+ SQL (0.0ms) SET standard_conforming_strings = on
165
+ SQL (0.0ms) SET client_min_messages TO 'notice'
166
+ SQL (1.0ms) SHOW TIME ZONE
167
+ SQL (0.0ms) SHOW client_min_messages
168
+ SQL (0.0ms) SET client_min_messages TO 'panic'
169
+ SQL (0.0ms) SET standard_conforming_strings = on
170
+ SQL (0.0ms) SET client_min_messages TO 'notice'
171
+ SQL (0.0ms) SHOW TIME ZONE
172
+ SQL (0.0ms) SHOW client_min_messages
173
+ SQL (0.0ms) SET client_min_messages TO 'panic'
174
+ SQL (0.0ms) SET standard_conforming_strings = on
175
+ SQL (0.0ms) SET client_min_messages TO 'notice'
176
+ SQL (0.0ms) SHOW TIME ZONE
177
+ SQL (0.0ms) SHOW client_min_messages
178
+ SQL (0.0ms) SET client_min_messages TO 'panic'
179
+ SQL (1.0ms) SET standard_conforming_strings = on
180
+ SQL (0.0ms) SET client_min_messages TO 'notice'
181
+ SQL (0.0ms) SHOW TIME ZONE
182
+ SQL (0.0ms) SHOW client_min_messages
183
+ SQL (0.0ms) SET client_min_messages TO 'panic'
184
+ SQL (0.0ms) SET standard_conforming_strings = on
185
+ SQL (0.0ms) SET client_min_messages TO 'notice'
186
+ SQL (0.0ms) SHOW TIME ZONE
187
+ SQL (1.0ms) SHOW client_min_messages
188
+ SQL (0.0ms) SET client_min_messages TO 'panic'
189
+ SQL (1.0ms) SET standard_conforming_strings = on
190
+ SQL (1.0ms) SET client_min_messages TO 'notice'
191
+ SQL (0.0ms) SHOW TIME ZONE
192
+ SQL (1.0ms) SHOW client_min_messages
193
+ SQL (0.0ms) SET client_min_messages TO 'panic'
194
+ SQL (0.0ms) SET standard_conforming_strings = on
195
+ SQL (1.0ms) SET client_min_messages TO 'notice'
196
+ SQL (0.0ms) SHOW TIME ZONE
197
+ SQL (1.0ms) SHOW client_min_messages
198
+ SQL (1.0ms) SHOW client_min_messages
199
+ SQL (1.0ms) SET client_min_messages TO 'panic'
200
+ SQL (0.0ms) SET standard_conforming_strings = on
201
+ SQL (0.0ms) SET client_min_messages TO 'notice'
202
+ SQL (0.0ms) SHOW TIME ZONE
203
+ PGError: ERROR: column memberships.user_idgroup_id does not exist
204
+ LINE 1: SELECT DISTINCT "memberships".user_idgroup_id FROM ...
205
+ ^
206
+ : SELECT DISTINCT "memberships".user_idgroup_id FROM "memberships" LEFT OUTER JOIN "membership_statuses" ON "membership_statuses"."user_id" = "memberships"."user_id" AND "membership_statuses"."group_id" = "memberships"."group_id" WHERE (membership_statuses.status = 'Active') LIMIT 1
207
+ SQL (0.0ms) SHOW client_min_messages
208
+ SQL (0.0ms) SET client_min_messages TO 'panic'
209
+ SQL (0.0ms) SET standard_conforming_strings = on
210
+ SQL (0.0ms) SET client_min_messages TO 'notice'
211
+ SQL (0.0ms) SHOW TIME ZONE
212
+ SQL (0.0ms) SHOW client_min_messages
213
+ SQL (0.0ms) SET client_min_messages TO 'panic'
214
+ SQL (0.0ms) SET standard_conforming_strings = on
215
+ SQL (0.0ms) SET client_min_messages TO 'notice'
216
+ SQL (0.0ms) SHOW TIME ZONE
217
+ SQL (1.0ms) SHOW client_min_messages
218
+ SQL (0.0ms) SET client_min_messages TO 'panic'
219
+ SQL (0.0ms) SET standard_conforming_strings = on
220
+ SQL (0.0ms) SET client_min_messages TO 'notice'
221
+ SQL (0.0ms) SHOW TIME ZONE
222
+ SQL (1.0ms) SHOW client_min_messages
223
+ SQL (1.0ms) SET client_min_messages TO 'panic'
224
+ SQL (0.0ms) SET standard_conforming_strings = on
225
+ SQL (0.0ms) SET client_min_messages TO 'notice'
226
+ SQL (0.0ms) SHOW TIME ZONE
227
+ SQL (0.0ms) SHOW client_min_messages
228
+ SQL (0.0ms) SET client_min_messages TO 'panic'
229
+ SQL (1.0ms) SET standard_conforming_strings = on
230
+ SQL (0.0ms) SET client_min_messages TO 'notice'
231
+ SQL (0.0ms) SHOW TIME ZONE
232
+ SQL (0.0ms) SHOW client_min_messages
233
+ SQL (0.0ms) SET client_min_messages TO 'panic'
234
+ SQL (0.0ms) SET standard_conforming_strings = on
235
+ SQL (0.0ms) SET client_min_messages TO 'notice'
236
+ SQL (0.0ms) SHOW TIME ZONE
237
+ SQL (0.0ms) SHOW client_min_messages
238
+ SQL (0.0ms) SET client_min_messages TO 'panic'
239
+ SQL (0.0ms) SET standard_conforming_strings = on
240
+ SQL (0.0ms) SET client_min_messages TO 'notice'
241
+ SQL (1.0ms) SHOW TIME ZONE
242
+ SQL (2.0ms) SHOW client_min_messages
243
+ SQL (0.0ms) SET client_min_messages TO 'panic'
244
+ SQL (0.0ms) SET standard_conforming_strings = on
245
+ SQL (0.0ms) SET client_min_messages TO 'notice'
246
+ SQL (0.0ms) SHOW TIME ZONE
247
+ SQL (0.0ms) SHOW client_min_messages
248
+ SQL (0.0ms) SET client_min_messages TO 'panic'
249
+ SQL (0.0ms) SET standard_conforming_strings = on
250
+ SQL (0.0ms) SET client_min_messages TO 'notice'
251
+ SQL (0.0ms) SHOW TIME ZONE
252
+ SQL (1.0ms) SHOW client_min_messages
253
+ SQL (1.0ms) SET client_min_messages TO 'panic'
254
+ SQL (0.0ms) SET standard_conforming_strings = on
255
+ SQL (0.0ms) SET client_min_messages TO 'notice'
256
+ SQL (0.0ms) SHOW TIME ZONE
257
+ SQL (0.0ms) SHOW client_min_messages
258
+ SQL (0.0ms) SET client_min_messages TO 'panic'
259
+ SQL (0.0ms) SET standard_conforming_strings = on
260
+ SQL (0.0ms) SET client_min_messages TO 'notice'
261
+ SQL (0.0ms) SHOW TIME ZONE
262
+ SQL (0.0ms) SHOW client_min_messages
263
+ SQL (0.0ms) SET client_min_messages TO 'panic'
264
+ SQL (1.0ms) SET standard_conforming_strings = on
265
+ SQL (1.0ms) SET client_min_messages TO 'notice'
266
+ SQL (0.0ms) SHOW TIME ZONE
267
+ SQL (1.0ms) SHOW client_min_messages
268
+ SQL (0.0ms) SET client_min_messages TO 'panic'
269
+ SQL (0.0ms) SET standard_conforming_strings = on
270
+ SQL (0.0ms) SET client_min_messages TO 'notice'
271
+ SQL (0.0ms) SHOW TIME ZONE
272
+ SQL (1.0ms) SHOW client_min_messages
273
+ SQL (0.0ms) SET client_min_messages TO 'panic'
274
+ SQL (0.0ms) SET standard_conforming_strings = on
275
+ SQL (0.0ms) SET client_min_messages TO 'notice'
276
+ SQL (0.0ms) SHOW TIME ZONE
@@ -129,8 +129,8 @@ class TestAssociations < ActiveSupport::TestCase
129
129
  end
130
130
 
131
131
  def test_has_and_belongs_to_many
132
- #@restaurant = Restaurant.find([1,1])
133
- #assert_equal 2, @restaurant.suburbs.size
132
+ @restaurant = Restaurant.find([1,1])
133
+ assert_equal 2, @restaurant.suburbs.size
134
134
 
135
135
  @restaurant = Restaurant.find([1,1], :include => :suburbs)
136
136
  assert_equal 2, @restaurant.suburbs.size
@@ -159,4 +159,23 @@ class TestAssociations < ActiveSupport::TestCase
159
159
 
160
160
  assert_equal [1, 1], @membership.id
161
161
  end
162
+
163
+ def test_has_many_with_primary_key_with_associations
164
+ # Trigger Active Records find_with_associations method
165
+ memberships = Membership.find(:all, :include => :statuses,
166
+ :conditions => ["membership_statuses.status = ?",
167
+ 'Active'])
168
+
169
+ assert_equal(1, memberships.length)
170
+ assert_equal([1,1], memberships[0].id)
171
+ end
172
+
173
+ def test_limitable_reflections
174
+ memberships = Membership.find(:all, :include => :statuses,
175
+ :conditions => ["membership_statuses.status = ?",
176
+ 'Active'],
177
+ :limit => 1)
178
+ assert_equal(1, memberships.length)
179
+ assert_equal([1,1], memberships[0].id)
180
+ end
162
181
  end
data/test/test_find.rb CHANGED
@@ -9,20 +9,20 @@ class TestFind < ActiveSupport::TestCase
9
9
  :class => ReferenceType,
10
10
  :primary_keys => [:reference_type_id],
11
11
  },
12
- :dual => {
12
+ :dual => {
13
13
  :class => ReferenceCode,
14
14
  :primary_keys => [:reference_type_id, :reference_code],
15
15
  },
16
- :dual_strs => {
16
+ :dual_strs => {
17
17
  :class => ReferenceCode,
18
18
  :primary_keys => ['reference_type_id', 'reference_code'],
19
19
  },
20
20
  }
21
-
21
+
22
22
  def setup
23
23
  self.class.classes = CLASSES
24
24
  end
25
-
25
+
26
26
  def test_find_first
27
27
  testing_with do
28
28
  obj = @klass.find(:first)
@@ -30,7 +30,7 @@ class TestFind < ActiveSupport::TestCase
30
30
  assert_equal @klass, obj.class
31
31
  end
32
32
  end
33
-
33
+
34
34
  def test_find
35
35
  testing_with do
36
36
  found = @klass.find(*first_id) # e.g. find(1,1) or find 1,1
@@ -40,7 +40,7 @@ class TestFind < ActiveSupport::TestCase
40
40
  assert_equal found, @klass.find(found.to_param)
41
41
  end
42
42
  end
43
-
43
+
44
44
  def test_find_composite_ids
45
45
  testing_with do
46
46
  found = @klass.find(first_id) # e.g. find([1,1].to_composite_ids)
@@ -50,16 +50,27 @@ class TestFind < ActiveSupport::TestCase
50
50
  assert_equal found, @klass.find(found.to_param)
51
51
  end
52
52
  end
53
-
53
+
54
54
  def things_to_look_at
55
55
  testing_with do
56
56
  assert_equal found, @klass.find(found.id.to_s) # fails for 2+ keys
57
57
  end
58
58
  end
59
-
59
+
60
60
  def test_not_found
61
61
  assert_raise(::ActiveRecord::RecordNotFound) do
62
62
  ReferenceCode.send :find, '999,999'
63
63
  end
64
64
  end
65
+
66
+ def test_find_last_suburb
67
+ suburb = Suburb.find(:last)
68
+ assert_equal([2,1], suburb.id)
69
+ end
70
+
71
+ def test_find_last_suburb_with_order
72
+ # Rails actually changes city_id DESC to city_id ASC
73
+ suburb = Suburb.find(:last, :order => 'suburbs.city_id DESC')
74
+ assert_equal([1,1], suburb.id)
75
+ end
65
76
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: composite_primary_keys
3
3
  version: !ruby/object:Gem::Version
4
- hash: 6629740
4
+ hash: 6629741
5
5
  prerelease: true
6
6
  segments:
7
7
  - 3
8
8
  - 0
9
9
  - 0
10
- - b2
11
- version: 3.0.0.b2
10
+ - b3
11
+ version: 3.0.0.b3
12
12
  platform: ruby
13
13
  authors:
14
14
  - Dr Nic Williams
@@ -17,7 +17,7 @@ autorequire:
17
17
  bindir: bin
18
18
  cert_chain: []
19
19
 
20
- date: 2010-11-06 00:00:00 -06:00
20
+ date: 2010-11-07 00:00:00 -06:00
21
21
  default_executable:
22
22
  dependencies:
23
23
  - !ruby/object:Gem::Dependency
@@ -86,6 +86,7 @@ files:
86
86
  - lib/composite_primary_keys/connection_adapters/sqlite3_adapter.rb
87
87
  - lib/composite_primary_keys/finder_methods.rb
88
88
  - lib/composite_primary_keys/fixtures.rb
89
+ - lib/composite_primary_keys/query_methods.rb
89
90
  - lib/composite_primary_keys/read.rb
90
91
  - lib/composite_primary_keys/reflection.rb
91
92
  - lib/composite_primary_keys/relation.rb
@@ -111,6 +112,7 @@ files:
111
112
  - test/connections/native_oracle_enhanced/connection.rb
112
113
  - test/connections/native_postgresql/connection.rb
113
114
  - test/connections/native_sqlite/connection.rb
115
+ - test/debug.log
114
116
  - test/fixtures/article.rb
115
117
  - test/fixtures/articles.yml
116
118
  - test/fixtures/article_group.rb
@@ -236,6 +238,7 @@ specification_version: 3
236
238
  summary: Composite key support for ActiveRecord
237
239
  test_files:
238
240
  - test/abstract_unit.rb
241
+ - test/debug.log
239
242
  - test/hash_tricks.rb
240
243
  - test/README_tests.txt
241
244
  - test/test_associations.rb