composite_primary_keys 0.6.1 → 0.6.2
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/lib/composite_primary_keys/associations.rb +7 -4
- data/lib/composite_primary_keys/version.rb +1 -1
- data/test/associations_test.rb +0 -7
- data/test/attributes_test.rb +2 -2
- data/test/clone_test.rb +1 -1
- data/test/create_test.rb +1 -1
- data/test/delete_test.rb +1 -1
- data/test/dummy_test.rb +1 -1
- data/test/fixtures/article.rb +5 -0
- data/test/fixtures/articles.yml +6 -0
- data/test/fixtures/db_definitions/mysql.drop.sql +3 -0
- data/test/fixtures/db_definitions/mysql.sql +20 -0
- data/test/fixtures/reading.rb +4 -0
- data/test/fixtures/readings.yml +10 -0
- data/test/fixtures/user.rb +5 -0
- data/test/fixtures/users.yml +6 -0
- data/test/miscellaneous_test.rb +1 -1
- data/test/pagination_test.rb +1 -1
- data/test/santiago_test.rb +27 -0
- data/test/update_test.rb +1 -1
- metadata +8 -1
@@ -206,16 +206,19 @@ module ActiveRecord::Associations
|
|
206
206
|
def full_keys(table_name, keys)
|
207
207
|
keys = keys.split(CompositePrimaryKeys::ID_SEP) if keys.is_a?(String)
|
208
208
|
keys.is_a?(Array) ?
|
209
|
-
keys.collect {|key| "#{table_name}.#{key}"}.join(CompositePrimaryKeys::ID_SEP) :
|
209
|
+
keys.collect {|key| "#{table_name}.#{key}"}.join(CompositePrimaryKeys::ID_SEP) :
|
210
210
|
"#{table_name}.#{keys}"
|
211
211
|
end
|
212
212
|
|
213
213
|
def full_columns_equals(table_name, keys, quoted_ids)
|
214
|
+
if keys.is_a?(Symbol) or (keys.is_a?(String) and keys == keys.split(CompositePrimaryKeys::ID_SEP))
|
215
|
+
return "#{table_name}.#{keys} = #{quoted_ids}"
|
216
|
+
end
|
214
217
|
keys = keys.split(CompositePrimaryKeys::ID_SEP) if keys.is_a?(String)
|
215
|
-
|
216
|
-
keys_ids = keys
|
218
|
+
quoted_ids = quoted_ids.split(CompositePrimaryKeys::ID_SEP) if quoted_ids.is_a?(String)
|
219
|
+
keys_ids = [keys, quoted_ids].transpose
|
217
220
|
keys_ids.collect {|key, id| "(#{table_name}.#{key} = #{id})"}.join(' AND ')
|
218
|
-
end
|
221
|
+
end
|
219
222
|
end
|
220
223
|
|
221
224
|
class HasManyAssociation < AssociationCollection #:nodoc:
|
data/test/associations_test.rb
CHANGED
@@ -81,11 +81,4 @@ class AssociationTest < Test::Unit::TestCase
|
|
81
81
|
|
82
82
|
end
|
83
83
|
|
84
|
-
def test_santiago
|
85
|
-
assert_not_nil @suburb = Suburb.find(1,1)
|
86
|
-
assert_equal 1, @suburb.streets.length
|
87
|
-
|
88
|
-
assert_not_nil @street = Street.find(1)
|
89
|
-
assert_not_nil @street.suburb
|
90
|
-
end
|
91
84
|
end
|
data/test/attributes_test.rb
CHANGED
@@ -11,7 +11,7 @@ class AttributesTest < Test::Unit::TestCase
|
|
11
11
|
CLASSES = {
|
12
12
|
:single => {
|
13
13
|
:class => ReferenceType,
|
14
|
-
:primary_keys =>
|
14
|
+
:primary_keys => :reference_type_id,
|
15
15
|
},
|
16
16
|
:dual => {
|
17
17
|
:class => ReferenceCode,
|
@@ -34,7 +34,7 @@ class AttributesTest < Test::Unit::TestCase
|
|
34
34
|
|
35
35
|
def test_brackets_primary_key
|
36
36
|
testing_with do
|
37
|
-
assert_equal @first.id, @first[@primary_keys]
|
37
|
+
assert_equal @first.id, @first[@primary_keys], "[] failing for #{@klass}"
|
38
38
|
assert_equal @first.id, @first[@first.class.primary_key]
|
39
39
|
end
|
40
40
|
end
|
data/test/clone_test.rb
CHANGED
data/test/create_test.rb
CHANGED
@@ -8,7 +8,7 @@ class DummyTest < Test::Unit::TestCase
|
|
8
8
|
CLASSES = {
|
9
9
|
:single => {
|
10
10
|
:class => ReferenceType,
|
11
|
-
:primary_keys =>
|
11
|
+
:primary_keys => :reference_type_id,
|
12
12
|
:create => {:reference_type_id => 10, :type_label => 'NEW_TYPE', :abbreviation => 'New Type'}
|
13
13
|
},
|
14
14
|
:dual => {
|
data/test/delete_test.rb
CHANGED
data/test/dummy_test.rb
CHANGED
@@ -50,3 +50,23 @@ CREATE TABLE `streets` (
|
|
50
50
|
PRIMARY KEY (`id`)
|
51
51
|
) TYPE=InnoDB;
|
52
52
|
|
53
|
+
CREATE TABLE `users` (
|
54
|
+
`id` int(11) NOT NULL auto_increment,
|
55
|
+
`name` varchar(50) NOT NULL,
|
56
|
+
PRIMARY KEY (`id`)
|
57
|
+
) TYPE=InnoDB;
|
58
|
+
|
59
|
+
CREATE TABLE `articles` (
|
60
|
+
`id` int(11) NOT NULL auto_increment,
|
61
|
+
`name` varchar(50) NOT NULL,
|
62
|
+
PRIMARY KEY (`id`)
|
63
|
+
) TYPE=InnoDB;
|
64
|
+
|
65
|
+
CREATE TABLE `readings` (
|
66
|
+
`id` int(11) NOT NULL auto_increment,
|
67
|
+
`user_id` int(11) NOT NULL,
|
68
|
+
`article_id` int(11) NOT NULL,
|
69
|
+
`rating` int(11) NOT NULL,
|
70
|
+
PRIMARY KEY (`id`)
|
71
|
+
) TYPE=InnoDB;
|
72
|
+
|
data/test/miscellaneous_test.rb
CHANGED
data/test/pagination_test.rb
CHANGED
@@ -0,0 +1,27 @@
|
|
1
|
+
# Test cases devised by Santiago that broke the Composite Primary Keys
|
2
|
+
# code at one point in time. But no more!!!
|
3
|
+
|
4
|
+
require 'abstract_unit'
|
5
|
+
require 'fixtures/user'
|
6
|
+
require 'fixtures/article'
|
7
|
+
require 'fixtures/reading'
|
8
|
+
|
9
|
+
class AssociationTest < Test::Unit::TestCase
|
10
|
+
fixtures :suburbs, :streets, :users, :articles, :readings
|
11
|
+
|
12
|
+
def test_normal_and_composite_associations
|
13
|
+
assert_not_nil @suburb = Suburb.find(1,1)
|
14
|
+
assert_equal 1, @suburb.streets.length
|
15
|
+
|
16
|
+
assert_not_nil @street = Street.find(1)
|
17
|
+
assert_not_nil @street.suburb
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_single_keys
|
21
|
+
@santiago = users(:santiago)
|
22
|
+
assert_not_nil @santiago.articles
|
23
|
+
assert_equal 2, @santiago.articles.length
|
24
|
+
assert_not_nil @santiago.readings
|
25
|
+
assert_equal 2, @santiago.readings.length
|
26
|
+
end
|
27
|
+
end
|
data/test/update_test.rb
CHANGED
metadata
CHANGED
@@ -3,7 +3,7 @@ rubygems_version: 0.8.11
|
|
3
3
|
specification_version: 1
|
4
4
|
name: composite_primary_keys
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.6.
|
6
|
+
version: 0.6.2
|
7
7
|
date: 2006-08-03 00:00:00 +02:00
|
8
8
|
summary: Support for composite primary keys in ActiveRecords
|
9
9
|
require_paths:
|
@@ -56,6 +56,7 @@ files:
|
|
56
56
|
- test/associations_test.rb
|
57
57
|
- test/attributes_test.rb
|
58
58
|
- test/create_test.rb
|
59
|
+
- test/santiago_test.rb
|
59
60
|
- test/connections/native_mysql
|
60
61
|
- test/connections/native_mysql/connection.rb
|
61
62
|
- test/fixtures/reference_type.rb
|
@@ -73,6 +74,12 @@ files:
|
|
73
74
|
- test/fixtures/suburb.rb
|
74
75
|
- test/fixtures/streets.yml
|
75
76
|
- test/fixtures/suburbs.yml
|
77
|
+
- test/fixtures/article.rb
|
78
|
+
- test/fixtures/user.rb
|
79
|
+
- test/fixtures/reading.rb
|
80
|
+
- test/fixtures/articles.yml
|
81
|
+
- test/fixtures/users.yml
|
82
|
+
- test/fixtures/readings.yml
|
76
83
|
- test/fixtures/db_definitions/mysql.drop.sql
|
77
84
|
- test/fixtures/db_definitions/mysql.sql
|
78
85
|
test_files: []
|