composite_primary_keys 1.0.1 → 1.0.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/History.txt +4 -0
- data/lib/composite_primary_keys/association_preload.rb +2 -1
- data/lib/composite_primary_keys/version.rb +1 -1
- data/test/fixtures/db_definitions/mysql.sql +23 -0
- data/test/fixtures/db_definitions/sqlite.sql +22 -1
- data/test/test_associations.rb +13 -1
- data/tmp/test.db +0 -0
- data/website/index.html +1 -1
- data/website/version-raw.js +1 -1
- data/website/version.js +1 -1
- metadata +2 -2
data/History.txt
CHANGED
@@ -57,7 +57,8 @@ module CompositePrimaryKeys
|
|
57
57
|
#add conditions from reflection!
|
58
58
|
through_records.first.class.preload_associations(through_records, source, reflection.options)
|
59
59
|
through_records.each do |through_record|
|
60
|
-
|
60
|
+
key = through_primary_key.to_s.split(CompositePrimaryKeys::ID_SEP).map{|k| through_record.send(k)}.join(CompositePrimaryKeys::ID_SEP)
|
61
|
+
add_preloaded_records_to_collection(id_to_record_map[key], reflection.name, through_record.send(source))
|
61
62
|
end
|
62
63
|
end
|
63
64
|
else
|
@@ -135,4 +135,27 @@ create table restaurants_suburbs (
|
|
135
135
|
store_id int(11) not null,
|
136
136
|
city_id int(11) not null,
|
137
137
|
suburb_id int(11) not null
|
138
|
+
) TYPE=InnoDB;
|
139
|
+
|
140
|
+
create table dorms (
|
141
|
+
id int(11) not null auto_increment,
|
142
|
+
primary key(id)
|
143
|
+
) TYPE=InnoDB;
|
144
|
+
|
145
|
+
create table rooms (
|
146
|
+
dorm_id int(11) not null,
|
147
|
+
room_id int(11) not null,
|
148
|
+
primary key (dorm_id, room_id)
|
149
|
+
) TYPE=InnoDB;
|
150
|
+
|
151
|
+
create table room_attributes (
|
152
|
+
id int(11) not null auto_increment,
|
153
|
+
name varchar(50),
|
154
|
+
primary key(id)
|
155
|
+
) TYPE=InnoDB;
|
156
|
+
|
157
|
+
create table room_attribute_assignments (
|
158
|
+
dorm_id int(11) not null,
|
159
|
+
room_id int(11) not null,
|
160
|
+
room_attribute_id integer not null
|
138
161
|
) TYPE=InnoDB;
|
@@ -124,4 +124,25 @@ create table restaurants_suburbs (
|
|
124
124
|
store_id integer not null,
|
125
125
|
city_id integer not null,
|
126
126
|
suburb_id integer not null
|
127
|
-
);
|
127
|
+
);
|
128
|
+
|
129
|
+
create table dorms (
|
130
|
+
id integer not null primary key autoincrement
|
131
|
+
);
|
132
|
+
|
133
|
+
create table rooms (
|
134
|
+
dorm_id integer not null,
|
135
|
+
room_id integer not null,
|
136
|
+
primary key (dorm_id, room_id)
|
137
|
+
);
|
138
|
+
|
139
|
+
create table room_attributes (
|
140
|
+
id integer not null primary key autoincrement,
|
141
|
+
name varchar(50)
|
142
|
+
);
|
143
|
+
|
144
|
+
create table room_attribute_assignments (
|
145
|
+
dorm_id integer not null,
|
146
|
+
room_id integer not null,
|
147
|
+
room_attribute_id integer not null
|
148
|
+
);
|
data/test/test_associations.rb
CHANGED
@@ -5,9 +5,14 @@ require 'fixtures/product_tariff'
|
|
5
5
|
require 'fixtures/suburb'
|
6
6
|
require 'fixtures/street'
|
7
7
|
require 'fixtures/restaurant'
|
8
|
+
require 'fixtures/dorm'
|
9
|
+
require 'fixtures/room'
|
10
|
+
require 'fixtures/room_attribute'
|
11
|
+
require 'fixtures/room_attribute_assignment'
|
8
12
|
|
9
13
|
class TestAssociations < Test::Unit::TestCase
|
10
|
-
fixtures :products, :tariffs, :product_tariffs, :suburbs, :streets, :restaurants, :restaurants_suburbs
|
14
|
+
fixtures :products, :tariffs, :product_tariffs, :suburbs, :streets, :restaurants, :restaurants_suburbs,
|
15
|
+
:dorms, :rooms, :room_attributes, :room_attribute_assignments
|
11
16
|
|
12
17
|
def test_quoted_table_columns
|
13
18
|
assert_equal "product_tariffs.product_id,product_tariffs.tariff_id,product_tariffs.tariff_start_date",
|
@@ -94,6 +99,13 @@ class TestAssociations < Test::Unit::TestCase
|
|
94
99
|
assert_equal 3, @products.inject(0) {|sum, product| sum + product.instance_variable_get('@tariffs').length},
|
95
100
|
"Incorrect number of tariffs returned"
|
96
101
|
end
|
102
|
+
|
103
|
+
def test_has_many_through_when_through_association_is_composite
|
104
|
+
dorm = Dorm.find(:first)
|
105
|
+
assert_equal 1, dorm.rooms.length
|
106
|
+
assert_equal 1, dorm.rooms.first.room_attributes.length
|
107
|
+
assert_equal 'keg', dorm.rooms.first.room_attributes.first.name
|
108
|
+
end
|
97
109
|
|
98
110
|
def test_associations_with_conditions
|
99
111
|
@suburb = Suburb.find([2, 1])
|
data/tmp/test.db
CHANGED
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">1.0.
|
36
|
+
<a href="http://rubyforge.org/projects/compositekeys" class="numbers">1.0.2</a>
|
37
37
|
</div>
|
38
38
|
<h1>→ Ruby on Rails</h1>
|
39
39
|
|
data/website/version-raw.js
CHANGED
data/website/version.js
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: composite_primary_keys
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dr Nic Williams
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2008-06-
|
12
|
+
date: 2008-06-07 00:00:00 -05:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|