composite_primary_keys 0.8.6 → 0.9.0
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 +9 -0
- data/Manifest.txt +37 -0
- data/README.txt +34 -9
- data/README_DB2.txt +33 -0
- data/Rakefile +8 -119
- data/init.rb +2 -0
- data/lib/adapter_helper/base.rb +63 -0
- data/lib/adapter_helper/mysql.rb +13 -0
- data/lib/adapter_helper/oracle.rb +13 -0
- data/lib/adapter_helper/postgresql.rb +13 -0
- data/lib/adapter_helper/sqlite3.rb +13 -0
- data/lib/composite_primary_keys.rb +2 -2
- data/lib/composite_primary_keys/associations.rb +53 -28
- data/lib/composite_primary_keys/base.rb +4 -1
- data/lib/composite_primary_keys/connection_adapters/ibm_db_adapter.rb +21 -0
- data/lib/composite_primary_keys/connection_adapters/postgresql_adapter.rb +1 -1
- data/lib/composite_primary_keys/migration.rb +13 -0
- data/lib/composite_primary_keys/version.rb +2 -2
- data/loader.rb +24 -0
- data/local/database_connections.rb.sample +10 -0
- data/local/paths.rb.sample +2 -0
- data/local/tasks.rb.sample +2 -0
- data/scripts/console.rb +25 -0
- data/tasks/activerecord_selection.rake +43 -0
- data/tasks/databases.rake +10 -0
- data/tasks/databases/mysql.rake +30 -0
- data/tasks/databases/oracle.rake +15 -0
- data/tasks/databases/postgresql.rake +26 -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 +2 -4
- data/test/connections/native_ibm_db/connection.rb +23 -0
- data/test/connections/native_mysql/connection.rb +8 -13
- data/test/connections/native_oracle/connection.rb +8 -11
- data/test/connections/native_postgresql/connection.rb +3 -9
- data/test/connections/native_sqlite/connection.rb +4 -5
- data/test/fixtures/comment.rb +5 -0
- data/test/fixtures/comments.yml +14 -0
- data/test/fixtures/db_definitions/db2-create-tables.sql +92 -0
- data/test/fixtures/db_definitions/db2-drop-tables.sql +13 -0
- data/test/fixtures/db_definitions/mysql.sql +24 -0
- data/test/fixtures/db_definitions/oracle.drop.sql +6 -0
- data/test/fixtures/db_definitions/oracle.sql +28 -1
- data/test/fixtures/db_definitions/postgresql.sql +24 -0
- data/test/fixtures/db_definitions/sqlite.sql +21 -0
- data/test/fixtures/department.rb +5 -0
- data/test/fixtures/departments.yml +3 -0
- data/test/fixtures/employee.rb +4 -0
- data/test/fixtures/employees.yml +9 -0
- data/test/fixtures/hack.rb +6 -0
- data/test/fixtures/hacks.yml +2 -0
- data/test/fixtures/product.rb +3 -2
- data/test/fixtures/streets.yml +11 -1
- data/test/fixtures/suburb.rb +2 -0
- data/test/fixtures/suburbs.yml +6 -1
- data/test/fixtures/user.rb +1 -0
- data/test/test_associations.rb +29 -5
- data/test/test_delete.rb +23 -2
- data/test/test_polymorphic.rb +24 -0
- data/tmp/test.db +0 -0
- data/website/index.html +2 -2
- data/website/version-raw.js +1 -1
- data/website/version.js +1 -1
- metadata +43 -3
@@ -19,3 +19,9 @@ drop sequence groups_seq;
|
|
19
19
|
drop table memberships;
|
20
20
|
drop table membership_statuses;
|
21
21
|
drop sequence membership_statuses_seq;
|
22
|
+
drop table departments;
|
23
|
+
drop table employees;
|
24
|
+
drop sequence employees_seq;
|
25
|
+
drop table comments;
|
26
|
+
drop sequence comments_seq;
|
27
|
+
drop table hacks;
|
@@ -108,4 +108,31 @@ create table membership_statuses (
|
|
108
108
|
|
109
109
|
create sequence membership_statuses_seq
|
110
110
|
start with 1000;
|
111
|
-
|
111
|
+
|
112
|
+
CREATE TABLE departments (
|
113
|
+
department_id number(11) NOT NULL,
|
114
|
+
location_id number(11) NOT NULL,
|
115
|
+
constraint departments_pk primary key(department_id, location_id)
|
116
|
+
);
|
117
|
+
|
118
|
+
CREATE TABLE employees (
|
119
|
+
id number(11) NOT NULL primary key,
|
120
|
+
department_id number(11) DEFAULT NULL,
|
121
|
+
location_id number(11) DEFAULT NULL
|
122
|
+
);
|
123
|
+
|
124
|
+
create sequence employees_seq
|
125
|
+
start with 1000;
|
126
|
+
|
127
|
+
CREATE TABLE comments (
|
128
|
+
id number(11) NOT NULL PRIMARY KEY,
|
129
|
+
person_id varchar(100) DEFAULT NULL,
|
130
|
+
person_type varchar(100) DEFAULT NULL
|
131
|
+
);
|
132
|
+
|
133
|
+
create sequence comments_seq
|
134
|
+
start with 1000;
|
135
|
+
|
136
|
+
CREATE TABLE hacks (
|
137
|
+
name varchar(50) NOT NULL PRIMARY KEY
|
138
|
+
);
|
@@ -98,3 +98,27 @@ CREATE TABLE membership_statuses (
|
|
98
98
|
PRIMARY KEY (id)
|
99
99
|
);
|
100
100
|
|
101
|
+
CREATE TABLE departments (
|
102
|
+
department_id int NOT NULL,
|
103
|
+
location_id int NOT NULL,
|
104
|
+
PRIMARY KEY (department_id, location_id)
|
105
|
+
);
|
106
|
+
|
107
|
+
CREATE TABLE employees (
|
108
|
+
id int NOT NULL,
|
109
|
+
department_id int DEFAULT NULL,
|
110
|
+
location_id int DEFAULT NULL,
|
111
|
+
PRIMARY KEY (id)
|
112
|
+
);
|
113
|
+
|
114
|
+
CREATE TABLE comments (
|
115
|
+
id int NOT NULL,
|
116
|
+
person_id varchar(100) DEFAULT NULL,
|
117
|
+
person_type varchar(100) DEFAULT NULL,
|
118
|
+
PRIMARY KEY (id)
|
119
|
+
);
|
120
|
+
|
121
|
+
CREATE TABLE hacks (
|
122
|
+
name varchar(50) NOT NULL,
|
123
|
+
PRIMARY KEY (name)
|
124
|
+
);
|
@@ -82,3 +82,24 @@ CREATE TABLE membership_statuses (
|
|
82
82
|
status varchar(50) NOT NULL
|
83
83
|
);
|
84
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
|
+
);
|
102
|
+
|
103
|
+
CREATE TABLE hacks (
|
104
|
+
name varchar(50) NOT NULL PRIMARY KEY
|
105
|
+
);
|
data/test/fixtures/product.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
class Product < ActiveRecord::Base
|
2
|
-
|
2
|
+
set_primary_keys :id # redundant
|
3
3
|
has_many :product_tariffs, :foreign_key => :product_id
|
4
4
|
has_one :product_tariff, :foreign_key => :product_id
|
5
|
-
|
5
|
+
|
6
|
+
has_many :tariffs, :through => :product_tariffs, :foreign_key => [:tariff_id, :tariff_start_date]
|
6
7
|
end
|
data/test/fixtures/streets.yml
CHANGED
data/test/fixtures/suburb.rb
CHANGED
@@ -1,4 +1,6 @@
|
|
1
1
|
class Suburb < ActiveRecord::Base
|
2
2
|
set_primary_keys :city_id, :suburb_id
|
3
3
|
has_many :streets, :foreign_key => [:city_id, :suburb_id]
|
4
|
+
has_many :first_streets, :foreign_key => [:city_id, :suburb_id],
|
5
|
+
:class_name => 'Street', :conditions => "streets.name = 'First Street'"
|
4
6
|
end
|
data/test/fixtures/suburbs.yml
CHANGED
data/test/fixtures/user.rb
CHANGED
data/test/test_associations.rb
CHANGED
@@ -78,13 +78,18 @@ class TestAssociations < Test::Unit::TestCase
|
|
78
78
|
assert_not_nil @product_tariffs.first.instance_variable_get('@product'), '@product not set'
|
79
79
|
end
|
80
80
|
|
81
|
-
def
|
82
|
-
|
83
|
-
|
84
|
-
|
81
|
+
def test_find_includes_comp_belongs_to_tariff
|
82
|
+
assert @product_tariffs = ProductTariff.find(:all, :include => :tariff)
|
83
|
+
assert_equal 3, @product_tariffs.length
|
84
|
+
assert_not_nil @product_tariffs.first.instance_variable_get('@tariff'), '@tariff not set'
|
85
|
+
end
|
86
|
+
|
87
|
+
def test_find_includes_extended
|
88
|
+
assert @products = Product.find(:all, :include => {:product_tariffs => :tariff})
|
89
|
+
assert_equal 3, @products.inject(0) {|sum, product| sum + product.instance_variable_get('@product_tariffs').length},
|
85
90
|
"Incorrect number of product_tariffs returned"
|
86
91
|
|
87
|
-
assert @tariffs = Tariff.find(:all, :include => {:product_tariffs => :
|
92
|
+
assert @tariffs = Tariff.find(:all, :include => {:product_tariffs => :product})
|
88
93
|
assert_equal 3, @tariffs.inject(0) {|sum, tariff| sum + tariff.instance_variable_get('@product_tariffs').length},
|
89
94
|
"Incorrect number of product_tariffs returned"
|
90
95
|
end
|
@@ -97,4 +102,23 @@ class TestAssociations < Test::Unit::TestCase
|
|
97
102
|
assert_equal('(foo=1 AND bar=2)', where_clause)
|
98
103
|
end
|
99
104
|
|
105
|
+
def test_has_many_through
|
106
|
+
@products = Product.find(:all, :include => :tariffs)
|
107
|
+
assert_equal 3, @products.inject(0) {|sum, product| sum + product.instance_variable_get('@tariffs').length},
|
108
|
+
"Incorrect number of tariffs returned"
|
109
|
+
end
|
110
|
+
|
111
|
+
def test_associations_with_conditions
|
112
|
+
@suburb = Suburb.find([2, 1])
|
113
|
+
assert_equal 2, @suburb.streets.size
|
114
|
+
|
115
|
+
@suburb = Suburb.find([2, 1])
|
116
|
+
assert_equal 1, @suburb.first_streets.size
|
117
|
+
|
118
|
+
@suburb = Suburb.find([2, 1], :include => :streets)
|
119
|
+
assert_equal 2, @suburb.streets.size
|
120
|
+
|
121
|
+
@suburb = Suburb.find([2, 1], :include => :first_streets)
|
122
|
+
assert_equal 1, @suburb.first_streets.size
|
123
|
+
end
|
100
124
|
end
|
data/test/test_delete.rb
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
require 'abstract_unit'
|
2
2
|
require 'fixtures/reference_type'
|
3
3
|
require 'fixtures/reference_code'
|
4
|
+
require 'fixtures/department'
|
5
|
+
require 'fixtures/employee'
|
4
6
|
|
5
7
|
class TestDelete < Test::Unit::TestCase
|
6
8
|
|
@@ -16,7 +18,7 @@ class TestDelete < Test::Unit::TestCase
|
|
16
18
|
}
|
17
19
|
|
18
20
|
def setup
|
19
|
-
create_fixtures :reference_types, :reference_codes
|
21
|
+
create_fixtures :reference_types, :reference_codes, :departments, :employees
|
20
22
|
self.class.classes = CLASSES
|
21
23
|
end
|
22
24
|
|
@@ -63,4 +65,23 @@ class TestDelete < Test::Unit::TestCase
|
|
63
65
|
@klass.delete_all
|
64
66
|
end
|
65
67
|
end
|
66
|
-
|
68
|
+
|
69
|
+
def test_clear_association
|
70
|
+
department = Department.find(1,1)
|
71
|
+
assert_equal 2, department.employees.size, "Employee count for department should be 2 before clear"
|
72
|
+
department.employees.clear
|
73
|
+
assert_equal 0, department.employees.size, "After clear size should 0"
|
74
|
+
department.reload
|
75
|
+
assert_equal 0, department.employees.size, "After clear count in database should have been 0"
|
76
|
+
end
|
77
|
+
|
78
|
+
def test_delete_association
|
79
|
+
department = Department.find(1,1)
|
80
|
+
assert_equal 2, department.employees.size , "Employee count for department should be 2 before delete"
|
81
|
+
first_employee = department.employees[0]
|
82
|
+
department.employees.delete(first_employee)
|
83
|
+
assert_equal 1, department.employees.size, "After delete employees count should be 1."
|
84
|
+
department.reload
|
85
|
+
assert_equal 1, department.employees.size, "After delete employees count should be 1 after reload from DB."
|
86
|
+
end
|
87
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'abstract_unit'
|
2
|
+
require 'fixtures/comment'
|
3
|
+
require 'fixtures/user'
|
4
|
+
require 'fixtures/employee'
|
5
|
+
require 'fixtures/hack'
|
6
|
+
|
7
|
+
class TestPolymorphic < Test::Unit::TestCase
|
8
|
+
|
9
|
+
def setup
|
10
|
+
create_fixtures :users, :employees, :comments, :hacks
|
11
|
+
end
|
12
|
+
|
13
|
+
|
14
|
+
def test_polymorphic_has_many
|
15
|
+
comments = Hack.find('andrew').comments
|
16
|
+
assert comments[0].person_id = 'andrew'
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_polymorphic_has_one
|
20
|
+
first_comment = Hack.find('andrew').first_comment
|
21
|
+
assert first_comment.person_id = 'andrew'
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
data/tmp/test.db
ADDED
Binary file
|
data/website/index.html
CHANGED
@@ -33,7 +33,7 @@
|
|
33
33
|
<h1>Composite Primary Keys</h1>
|
34
34
|
<div id="version" class="clickable" onclick='document.location = "http://rubyforge.org/projects/compositekeys"; return false'>
|
35
35
|
Get Version
|
36
|
-
<a href="http://rubyforge.org/projects/compositekeys" class="numbers">0.
|
36
|
+
<a href="http://rubyforge.org/projects/compositekeys" class="numbers">0.9.0</a>
|
37
37
|
</div>
|
38
38
|
<h1>→ Ruby on Rails</h1>
|
39
39
|
|
@@ -291,7 +291,7 @@ other stories and things.</p>
|
|
291
291
|
|
292
292
|
<p>Comments are welcome. Send an email to <a href="mailto:drnicwilliams@gmail.com">Dr Nic Williams</a>.</p>
|
293
293
|
<p class="coda">
|
294
|
-
<a href="mailto:drnicwilliams@gmail.com">Dr Nic</a>,
|
294
|
+
<a href="mailto:drnicwilliams@gmail.com">Dr Nic</a>, 16th August 2007<br>
|
295
295
|
Theme extended from <a href="http://rb2js.rubyforge.org/">Paul Battley</a>
|
296
296
|
</p>
|
297
297
|
</div>
|
data/website/version-raw.js
CHANGED
data/website/version.js
CHANGED
metadata
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
|
-
rubygems_version: 0.9.4.
|
2
|
+
rubygems_version: 0.9.4.3
|
3
3
|
specification_version: 1
|
4
4
|
name: composite_primary_keys
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.
|
7
|
-
date: 2007-
|
6
|
+
version: 0.9.0
|
7
|
+
date: 2007-09-28 00:00:00 +10:00
|
8
8
|
summary: Composite key support for ActiveRecords
|
9
9
|
require_paths:
|
10
10
|
- lib
|
@@ -32,35 +32,70 @@ files:
|
|
32
32
|
- History.txt
|
33
33
|
- Manifest.txt
|
34
34
|
- README.txt
|
35
|
+
- README_DB2.txt
|
35
36
|
- Rakefile
|
37
|
+
- init.rb
|
36
38
|
- install.rb
|
39
|
+
- lib/adapter_helper/base.rb
|
40
|
+
- lib/adapter_helper/mysql.rb
|
41
|
+
- lib/adapter_helper/oracle.rb
|
42
|
+
- lib/adapter_helper/postgresql.rb
|
43
|
+
- lib/adapter_helper/sqlite3.rb
|
37
44
|
- lib/composite_primary_keys.rb
|
38
45
|
- lib/composite_primary_keys/associations.rb
|
39
46
|
- lib/composite_primary_keys/base.rb
|
40
47
|
- lib/composite_primary_keys/calculations.rb
|
41
48
|
- lib/composite_primary_keys/composite_arrays.rb
|
49
|
+
- lib/composite_primary_keys/connection_adapters/ibm_db_adapter.rb
|
42
50
|
- lib/composite_primary_keys/connection_adapters/oracle_adapter.rb
|
43
51
|
- lib/composite_primary_keys/connection_adapters/postgresql_adapter.rb
|
44
52
|
- lib/composite_primary_keys/fixtures.rb
|
53
|
+
- lib/composite_primary_keys/migration.rb
|
45
54
|
- lib/composite_primary_keys/reflection.rb
|
46
55
|
- lib/composite_primary_keys/version.rb
|
56
|
+
- loader.rb
|
57
|
+
- local/database_connections.rb.sample
|
58
|
+
- local/paths.rb.sample
|
59
|
+
- local/tasks.rb.sample
|
60
|
+
- scripts/console.rb
|
47
61
|
- scripts/txt2html
|
48
62
|
- scripts/txt2js
|
63
|
+
- tasks/activerecord_selection.rake
|
64
|
+
- tasks/databases.rake
|
65
|
+
- tasks/databases/mysql.rake
|
66
|
+
- tasks/databases/oracle.rake
|
67
|
+
- tasks/databases/postgresql.rake
|
68
|
+
- tasks/databases/sqlite3.rake
|
69
|
+
- tasks/deployment.rake
|
70
|
+
- tasks/local_setup.rake
|
71
|
+
- tasks/website.rake
|
72
|
+
- test/README_tests.txt
|
49
73
|
- test/abstract_unit.rb
|
50
74
|
- test/composite_arrays_test.rb
|
75
|
+
- test/connections/native_ibm_db/connection.rb
|
51
76
|
- test/connections/native_mysql/connection.rb
|
52
77
|
- test/connections/native_oracle/connection.rb
|
53
78
|
- test/connections/native_postgresql/connection.rb
|
54
79
|
- test/connections/native_sqlite/connection.rb
|
55
80
|
- test/fixtures/article.rb
|
56
81
|
- test/fixtures/articles.yml
|
82
|
+
- test/fixtures/comment.rb
|
83
|
+
- test/fixtures/comments.yml
|
84
|
+
- test/fixtures/db_definitions/db2-create-tables.sql
|
85
|
+
- test/fixtures/db_definitions/db2-drop-tables.sql
|
57
86
|
- test/fixtures/db_definitions/mysql.sql
|
58
87
|
- test/fixtures/db_definitions/oracle.drop.sql
|
59
88
|
- test/fixtures/db_definitions/oracle.sql
|
60
89
|
- test/fixtures/db_definitions/postgresql.sql
|
61
90
|
- test/fixtures/db_definitions/sqlite.sql
|
91
|
+
- test/fixtures/department.rb
|
92
|
+
- test/fixtures/departments.yml
|
93
|
+
- test/fixtures/employee.rb
|
94
|
+
- test/fixtures/employees.yml
|
62
95
|
- test/fixtures/group.rb
|
63
96
|
- test/fixtures/groups.yml
|
97
|
+
- test/fixtures/hack.rb
|
98
|
+
- test/fixtures/hacks.yml
|
64
99
|
- test/fixtures/membership.rb
|
65
100
|
- test/fixtures/membership_status.rb
|
66
101
|
- test/fixtures/membership_statuses.yml
|
@@ -94,9 +129,11 @@ files:
|
|
94
129
|
- test/test_ids.rb
|
95
130
|
- test/test_miscellaneous.rb
|
96
131
|
- test/test_pagination.rb
|
132
|
+
- test/test_polymorphic.rb
|
97
133
|
- test/test_santiago.rb
|
98
134
|
- test/test_tutorial_examle.rb
|
99
135
|
- test/test_update.rb
|
136
|
+
- tmp/test.db
|
100
137
|
- website/index.html
|
101
138
|
- website/index.txt
|
102
139
|
- website/javascripts/rounded_corners_lite.inc.js
|
@@ -118,6 +155,7 @@ test_files:
|
|
118
155
|
- test/test_ids.rb
|
119
156
|
- test/test_miscellaneous.rb
|
120
157
|
- test/test_pagination.rb
|
158
|
+
- test/test_polymorphic.rb
|
121
159
|
- test/test_santiago.rb
|
122
160
|
- test/test_tutorial_examle.rb
|
123
161
|
- test/test_update.rb
|
@@ -128,6 +166,8 @@ extra_rdoc_files:
|
|
128
166
|
- History.txt
|
129
167
|
- Manifest.txt
|
130
168
|
- README.txt
|
169
|
+
- README_DB2.txt
|
170
|
+
- test/README_tests.txt
|
131
171
|
- website/index.txt
|
132
172
|
- website/version-raw.txt
|
133
173
|
- website/version.txt
|