composite_primary_keys 3.1.8 → 3.1.9
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 +16 -12
- data/Rakefile +2 -4
- data/lib/composite_primary_keys/version.rb +1 -1
- data/test/connections/native_mysql/connection.rb +1 -1
- data/test/connections/native_oracle/connection.rb +1 -1
- data/test/connections/native_oracle_enhanced/connection.rb +1 -1
- data/test/connections/native_postgresql/connection.rb +1 -1
- data/test/connections/native_sqlite/connection.rb +1 -1
- data/test/fixtures/article.rb +1 -1
- data/test/fixtures/comment.rb +0 -1
- data/test/fixtures/db_definitions/db2-create-tables.sql +4 -13
- data/test/fixtures/db_definitions/db2-drop-tables.sql +1 -1
- data/test/fixtures/db_definitions/mysql.sql +5 -13
- data/test/fixtures/db_definitions/oracle.drop.sql +1 -2
- data/test/fixtures/db_definitions/oracle.sql +4 -13
- data/test/fixtures/db_definitions/postgresql.sql +5 -13
- data/test/fixtures/db_definitions/sqlite.sql +4 -13
- data/test/fixtures/department.rb +1 -0
- data/test/fixtures/departments.yml +5 -1
- data/test/fixtures/employees.yml +12 -2
- data/test/fixtures/membership.rb +0 -2
- data/test/fixtures/product.rb +4 -2
- data/test/fixtures/restaurant.rb +4 -1
- data/test/fixtures/restaurants.yml +8 -1
- data/test/fixtures/tariff.rb +0 -1
- data/test/fixtures/tariffs.yml +2 -0
- data/test/test_associations.rb +6 -23
- data/test/test_attribute_methods.rb +5 -6
- data/test/test_delete.rb +35 -2
- data/test/test_habtm.rb +42 -0
- data/test/test_ids.rb +0 -8
- data/test/test_suite.rb +1 -0
- metadata +6 -23
- data/lib/composite_primary_keys/associations/association.rb +0 -23
- data/lib/composite_primary_keys/associations/association_scope.rb +0 -67
- data/lib/composite_primary_keys/associations/join_dependency/join_association.rb +0 -22
- data/lib/composite_primary_keys/associations/join_dependency/join_part.rb +0 -39
- data/lib/composite_primary_keys/associations/preloader/association.rb +0 -61
- data/lib/composite_primary_keys/associations/preloader/belongs_to.rb +0 -13
- data/lib/composite_primary_keys/associations/preloader/has_and_belongs_to_many.rb +0 -46
- data/lib/composite_primary_keys/attribute_methods/primary_key.rb +0 -19
- data/lib/composite_primary_keys/attribute_methods/read.rb +0 -88
- data/lib/composite_primary_keys/attribute_methods/write.rb +0 -40
- data/lib/composite_primary_keys/composite_predicates.rb +0 -44
- data/lib/composite_primary_keys/named_scope.rb +0 -29
- data/lib/composite_primary_keys/relation/finder_methods.rb +0 -119
- data/lib/composite_primary_keys/relation/query_methods.rb +0 -24
- data/test/fixtures/article_group.rb +0 -4
- data/test/fixtures/article_groups.yml +0 -7
- data/test/fixtures/kitchen_sink.rb +0 -3
- data/test/fixtures/kitchen_sinks.yml +0 -5
- data/test/fixtures/way_node.rb +0 -3
data/History.txt
CHANGED
@@ -1,30 +1,34 @@
|
|
1
|
+
== 3.1.9 2011-06-04
|
2
|
+
* Improve HABTM association tests (David Rueck)
|
3
|
+
* Remove deprecated Rake tasks (Charlie Savage)
|
4
|
+
|
1
5
|
== 3.1.8 2011-05-26
|
2
6
|
* Fix calling clear on a HABTM associate (David Rueck)
|
3
7
|
|
4
8
|
== 3.1.7 2011-05-26
|
5
9
|
* Support regular AR models having one or many composite models (Jacques Fuentes)
|
6
|
-
* Minor test cleanup
|
7
|
-
* Make version requirements more explicit
|
8
|
-
* Remove Arel extensions used for calculations
|
10
|
+
* Minor test cleanup (Charlie Savage)
|
11
|
+
* Make version requirements more explicit (Charlie Savage)
|
12
|
+
* Remove Arel extensions used for calculations (Charlie Savage)
|
9
13
|
|
10
14
|
== 3.1.6 2011-04-03
|
11
|
-
* Updated belongs_to association to be a bit more flexible with non-CPK
|
15
|
+
* Updated belongs_to association to be a bit more flexible with non-CPK (Charlie Savage)
|
12
16
|
base models (Jacques Fuentes)
|
13
17
|
* Fix uniqueness check (David Rueck)
|
14
18
|
* Fix write issue when one of they keys in a composite key is
|
15
19
|
called id (Tom Hughes)
|
16
20
|
|
17
21
|
== 3.1.5 2011-03-24
|
18
|
-
* Fix simple calculation methods
|
19
|
-
* Fix instantiation of cpk records via associations
|
20
|
-
* Fix Relation#delete
|
21
|
-
* Fix Relation#destroy
|
22
|
+
* Fix simple calculation methods (Charlie Savage)
|
23
|
+
* Fix instantiation of cpk records via associations (Charlie Savage)
|
24
|
+
* Fix Relation#delete (Charlie Savage)
|
25
|
+
* Fix Relation#destroy (Charlie Savage)
|
22
26
|
|
23
27
|
== 3.1.4 2011-03-06
|
24
|
-
* Support ActiveRecord 3.0.5
|
25
|
-
replaced by interpolate_and_sanitize_sql)
|
26
|
-
* Fix persistence methods to support destroy callbacks
|
27
|
-
* Support rake 0.9.0 beta
|
28
|
+
* Support ActiveRecord 3.0.5 - interpolate_sql was removed and
|
29
|
+
replaced by interpolate_and_sanitize_sql (Charlie Savage)
|
30
|
+
* Fix persistence methods to support destroy callbacks (Charlie Savage)
|
31
|
+
* Support rake 0.9.0 beta (Charlie Savage)
|
28
32
|
|
29
33
|
|
30
34
|
== 3.1.2 2011-02-26
|
data/Rakefile
CHANGED
@@ -2,9 +2,7 @@ require 'rubygems'
|
|
2
2
|
require 'rake'
|
3
3
|
require 'rake/clean'
|
4
4
|
require 'rake/testtask'
|
5
|
-
require '
|
6
|
-
require 'rake/packagetask'
|
7
|
-
require 'rake/gempackagetask'
|
5
|
+
require 'rubygems/package_task'
|
8
6
|
|
9
7
|
# Set global variable so other tasks can access them
|
10
8
|
::PROJECT_ROOT = File.expand_path(".")
|
@@ -14,7 +12,7 @@ require 'rake/gempackagetask'
|
|
14
12
|
spec = Gem::Specification.load("#{GEM_NAME}.gemspec")
|
15
13
|
|
16
14
|
# Setup Rake tasks for managing the gem
|
17
|
-
|
15
|
+
Gem::PackageTask.new(spec).define
|
18
16
|
|
19
17
|
# Now load in other task files
|
20
18
|
Dir.glob('tasks/**/*.rake').each do |rake_file|
|
@@ -1,6 +1,6 @@
|
|
1
1
|
print "Using native Postgresql\n"
|
2
2
|
|
3
|
-
require '
|
3
|
+
require File.join(PROJECT_ROOT, 'lib', 'composite_primary_keys')
|
4
4
|
require File.join(PROJECT_ROOT, 'test', 'connections', 'connection_spec')
|
5
5
|
require File.join(PROJECT_ROOT, 'lib', 'composite_primary_keys', 'connection_adapters', 'postgresql_adapter')
|
6
6
|
|
data/test/fixtures/article.rb
CHANGED
data/test/fixtures/comment.rb
CHANGED
@@ -90,14 +90,6 @@ CREATE TABLE membership_statuses (
|
|
90
90
|
PRIMARY KEY (id)
|
91
91
|
);
|
92
92
|
|
93
|
-
create table kitchen_sinks (
|
94
|
-
id_1 integer not null,
|
95
|
-
id_2 integer not null,
|
96
|
-
a_date date,
|
97
|
-
a_string varchar(100),
|
98
|
-
primary key (id_1, id_2)
|
99
|
-
);
|
100
|
-
|
101
93
|
create table restaurants (
|
102
94
|
franchise_id integer not null,
|
103
95
|
store_id integer not null,
|
@@ -112,9 +104,8 @@ create table restaurants_suburbs (
|
|
112
104
|
suburb_id integer not null
|
113
105
|
);
|
114
106
|
|
115
|
-
create table
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
primary key (id, sequence_id)
|
107
|
+
create table products_restaurants (
|
108
|
+
product_id integer not null,
|
109
|
+
franchise_id integer not null,
|
110
|
+
store_id integer not null
|
120
111
|
);
|
@@ -116,14 +116,6 @@ create table hacks (
|
|
116
116
|
primary key (name)
|
117
117
|
) type=InnoDB;
|
118
118
|
|
119
|
-
create table kitchen_sinks (
|
120
|
-
id_1 int(11) not null,
|
121
|
-
id_2 int(11) not null,
|
122
|
-
a_date date,
|
123
|
-
a_string varchar(100),
|
124
|
-
primary key (id_1, id_2)
|
125
|
-
) type=InnoDB;
|
126
|
-
|
127
119
|
create table restaurants (
|
128
120
|
franchise_id int(11) not null,
|
129
121
|
store_id int(11) not null,
|
@@ -185,9 +177,9 @@ create table capitols (
|
|
185
177
|
primary key (country, city)
|
186
178
|
) type=InnoDB;
|
187
179
|
|
188
|
-
create table
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
primary key (id, sequence_id)
|
180
|
+
create table products_restaurants (
|
181
|
+
product_id int(11) not null,
|
182
|
+
franchise_id int(11) not null,
|
183
|
+
store_id int(11) not null
|
193
184
|
) type=InnoDB;
|
185
|
+
|
@@ -25,7 +25,6 @@ drop sequence employees_seq;
|
|
25
25
|
drop table comments;
|
26
26
|
drop sequence comments_seq;
|
27
27
|
drop table hacks;
|
28
|
-
drop table kitchen_sinks;
|
29
28
|
drop table restaurants;
|
30
29
|
drop table restaurants_suburbs;
|
31
30
|
drop table dorms;
|
@@ -37,4 +36,4 @@ drop table room_attribute_assignments;
|
|
37
36
|
drop table room_assignments;
|
38
37
|
drop table students;
|
39
38
|
drop sequence students_seq;
|
40
|
-
drop table
|
39
|
+
drop table products_restaurants;
|
@@ -124,14 +124,6 @@ create table hacks (
|
|
124
124
|
name varchar(50) not null primary key
|
125
125
|
);
|
126
126
|
|
127
|
-
create table kitchen_sinks (
|
128
|
-
id_1 number(11) not null,
|
129
|
-
id_2 number(11) not null,
|
130
|
-
a_date date,
|
131
|
-
a_string varchar(100),
|
132
|
-
constraint kitchen_sinks_pk primary key (id_1, id_2)
|
133
|
-
);
|
134
|
-
|
135
127
|
create table restaurants (
|
136
128
|
franchise_id number(11) not null,
|
137
129
|
store_id number(11) not null,
|
@@ -186,9 +178,8 @@ create table room_assignments (
|
|
186
178
|
room_id number(11) not null
|
187
179
|
);
|
188
180
|
|
189
|
-
create table
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
constraint way_nodes_pk primary key (id, sequence_id)
|
181
|
+
create table products_restaurants (
|
182
|
+
product_id number(11) not null,
|
183
|
+
franchise_id number(11) not null,
|
184
|
+
store_id number(11) not null
|
194
185
|
);
|
@@ -136,14 +136,6 @@ create table hacks (
|
|
136
136
|
primary key (name)
|
137
137
|
);
|
138
138
|
|
139
|
-
create table kitchen_sinks (
|
140
|
-
id_1 int not null,
|
141
|
-
id_2 int not null,
|
142
|
-
a_date date,
|
143
|
-
a_string varchar(100),
|
144
|
-
primary key (id_1, id_2)
|
145
|
-
);
|
146
|
-
|
147
139
|
create table restaurants (
|
148
140
|
franchise_id int not null,
|
149
141
|
store_id int not null,
|
@@ -211,9 +203,9 @@ create table capitols (
|
|
211
203
|
primary key (country, city)
|
212
204
|
);
|
213
205
|
|
214
|
-
create table
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
primary key (id, sequence_id)
|
206
|
+
create table products_restaurants (
|
207
|
+
product_id int not null,
|
208
|
+
franchise_id int not null,
|
209
|
+
store_id int not null
|
219
210
|
);
|
211
|
+
|
@@ -105,14 +105,6 @@ create table hacks (
|
|
105
105
|
name varchar(50) not null primary key
|
106
106
|
);
|
107
107
|
|
108
|
-
create table kitchen_sinks (
|
109
|
-
id_1 integer not null,
|
110
|
-
id_2 integer not null,
|
111
|
-
a_date date,
|
112
|
-
a_string varchar(100),
|
113
|
-
primary key (id_1, id_2)
|
114
|
-
);
|
115
|
-
|
116
108
|
create table restaurants (
|
117
109
|
franchise_id integer not null,
|
118
110
|
store_id integer not null,
|
@@ -171,9 +163,8 @@ create table capitols (
|
|
171
163
|
primary key (country, city)
|
172
164
|
);
|
173
165
|
|
174
|
-
create table
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
primary key (id, sequence_id)
|
166
|
+
create table products_restaurants (
|
167
|
+
product_id integer not null,
|
168
|
+
franchise_id integer not null,
|
169
|
+
store_id integer not null
|
179
170
|
);
|
data/test/fixtures/department.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
class Department < ActiveRecord::Base
|
2
2
|
set_primary_keys :department_id, :location_id
|
3
3
|
has_many :employees, :foreign_key => [:department_id, :location_id]
|
4
|
+
has_one :head, :class_name => 'Employee', :foreign_key => [:department_id, :location_id], :dependent => :delete
|
4
5
|
end
|
data/test/fixtures/employees.yml
CHANGED
@@ -1,9 +1,19 @@
|
|
1
|
-
|
1
|
+
steve:
|
2
2
|
id: 1
|
3
3
|
department_id: 1
|
4
4
|
location_id: 1
|
5
|
-
|
5
|
+
|
6
|
+
jill:
|
6
7
|
id: 2
|
7
8
|
department_id: 1
|
8
9
|
location_id: 1
|
9
10
|
|
11
|
+
sarah:
|
12
|
+
id: 3
|
13
|
+
department_id: 2
|
14
|
+
location_id: 1
|
15
|
+
|
16
|
+
robert:
|
17
|
+
id: 4
|
18
|
+
department_id: 2
|
19
|
+
location_id: 1
|
data/test/fixtures/membership.rb
CHANGED
@@ -4,7 +4,5 @@ class Membership < ActiveRecord::Base
|
|
4
4
|
belongs_to :user
|
5
5
|
belongs_to :group
|
6
6
|
has_many :statuses, :class_name => 'MembershipStatus', :foreign_key => [:user_id, :group_id]
|
7
|
-
|
8
7
|
has_many :readings, :primary_key => :user_id, :foreign_key => :user_id
|
9
|
-
has_one :reading, :primary_key => :user_id, :foreign_key => :user_id, :order => 'id DESC'
|
10
8
|
end
|
data/test/fixtures/product.rb
CHANGED
@@ -1,7 +1,9 @@
|
|
1
1
|
class Product < ActiveRecord::Base
|
2
2
|
set_primary_keys :id # redundant
|
3
3
|
has_many :product_tariffs, :foreign_key => :product_id, :dependent => :delete_all
|
4
|
-
# Yeah, this is fake, it uses for testing
|
5
|
-
has_one :product_tariff, :foreign_key => :product_id
|
6
4
|
has_many :tariffs, :through => :product_tariffs, :foreign_key => [:tariff_id, :tariff_start_date]
|
5
|
+
|
6
|
+
has_and_belongs_to_many :restaurants,
|
7
|
+
:foreign_key => :product_id,
|
8
|
+
:association_foreign_key => [:franchise_id, :store_id]
|
7
9
|
end
|
data/test/fixtures/restaurant.rb
CHANGED
@@ -3,4 +3,7 @@ class Restaurant < ActiveRecord::Base
|
|
3
3
|
has_and_belongs_to_many :suburbs,
|
4
4
|
:foreign_key => [:franchise_id, :store_id],
|
5
5
|
:association_foreign_key => [:city_id, :suburb_id]
|
6
|
-
|
6
|
+
has_and_belongs_to_many :products,
|
7
|
+
:foreign_key => [:franchise_id, :store_id],
|
8
|
+
:association_foreign_key => :product_id
|
9
|
+
end
|
data/test/fixtures/tariff.rb
CHANGED
@@ -1,6 +1,5 @@
|
|
1
1
|
class Tariff < ActiveRecord::Base
|
2
2
|
set_primary_keys [:tariff_id, :start_date]
|
3
3
|
has_many :product_tariffs, :foreign_key => [:tariff_id, :tariff_start_date]
|
4
|
-
has_one :product_tariff, :foreign_key => [:tariff_id, :tariff_start_date]
|
5
4
|
has_many :products, :through => :product_tariffs, :foreign_key => [:tariff_id, :tariff_start_date]
|
6
5
|
end
|
data/test/fixtures/tariffs.yml
CHANGED
data/test/test_associations.rb
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
require 'abstract_unit'
|
2
2
|
|
3
3
|
class TestAssociations < ActiveSupport::TestCase
|
4
|
-
fixtures :articles, :products, :tariffs, :product_tariffs, :suburbs, :streets, :restaurants,
|
4
|
+
fixtures :articles, :products, :tariffs, :product_tariffs, :suburbs, :streets, :restaurants,
|
5
5
|
:dorms, :rooms, :room_attributes, :room_attribute_assignments, :students, :room_assignments, :users, :readings,
|
6
|
-
:memberships
|
6
|
+
:departments, :memberships
|
7
7
|
|
8
8
|
def test_count
|
9
9
|
assert_equal(2, Product.count(:include => :product_tariffs))
|
@@ -20,7 +20,6 @@ class TestAssociations < ActiveSupport::TestCase
|
|
20
20
|
assert_equal 2, products(:first_product).product_tariffs.length
|
21
21
|
assert_not_nil products(:first_product).tariffs
|
22
22
|
assert_equal 2, products(:first_product).tariffs.length
|
23
|
-
assert_not_nil products(:first_product).product_tariff
|
24
23
|
end
|
25
24
|
|
26
25
|
def test_product_tariffs
|
@@ -35,7 +34,6 @@ class TestAssociations < ActiveSupport::TestCase
|
|
35
34
|
assert_equal 1, tariffs(:flat).product_tariffs.length
|
36
35
|
assert_not_nil tariffs(:flat).products
|
37
36
|
assert_equal 1, tariffs(:flat).products.length
|
38
|
-
assert_not_nil tariffs(:flat).product_tariff
|
39
37
|
end
|
40
38
|
|
41
39
|
# Its not generating the instances of associated classes from the rows
|
@@ -152,22 +150,6 @@ class TestAssociations < ActiveSupport::TestCase
|
|
152
150
|
assert_equal(rooms(:branner_room_1), room_assignment.room)
|
153
151
|
end
|
154
152
|
|
155
|
-
def test_has_and_belongs_to_many
|
156
|
-
@restaurant = Restaurant.find([1,1])
|
157
|
-
assert_equal 2, @restaurant.suburbs.size
|
158
|
-
|
159
|
-
@restaurant = Restaurant.find([1,1], :include => :suburbs)
|
160
|
-
assert_equal 2, @restaurant.suburbs.size
|
161
|
-
end
|
162
|
-
|
163
|
-
def test_habtm_clear
|
164
|
-
@restaurant = Restaurant.find([1,1])
|
165
|
-
assert_equal 2, @restaurant.suburbs.size
|
166
|
-
@restaurant.suburbs.clear
|
167
|
-
@restaurant = Restaurant.find([1,1])
|
168
|
-
assert_equal 0, @restaurant.suburbs.size
|
169
|
-
end
|
170
|
-
|
171
153
|
def test_has_many_with_primary_key
|
172
154
|
@membership = Membership.find([1, 1])
|
173
155
|
assert_equal 2, @membership.reading.id
|
@@ -175,8 +157,8 @@ class TestAssociations < ActiveSupport::TestCase
|
|
175
157
|
|
176
158
|
def test_has_one_with_composite
|
177
159
|
# In this case a regular model has_one composite model
|
178
|
-
|
179
|
-
assert_not_nil(
|
160
|
+
department = departments(:engineering)
|
161
|
+
assert_not_nil(department.head)
|
180
162
|
end
|
181
163
|
|
182
164
|
def test_has_many_with_primary_key
|
@@ -200,7 +182,8 @@ class TestAssociations < ActiveSupport::TestCase
|
|
200
182
|
end
|
201
183
|
|
202
184
|
def test_joins_has_one_with_primary_key
|
203
|
-
@membership = Membership.find(:first, :joins => :
|
185
|
+
@membership = Membership.find(:first, :joins => :readings,
|
186
|
+
:conditions => { :readings => { :id => 2 } })
|
204
187
|
|
205
188
|
assert_equal [1, 1], @membership.id
|
206
189
|
end
|