composite_primary_keys 1.1.0 → 2.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +4 -0
- data/Rakefile +1 -1
- data/lib/composite_primary_keys/association_preload.rb +19 -2
- data/lib/composite_primary_keys/associations.rb +2 -2
- data/lib/composite_primary_keys/calculations.rb +2 -1
- data/lib/composite_primary_keys/version.rb +2 -2
- data/tmp/test.db +0 -0
- data/website/index.html +4 -4
- data/website/index.txt +2 -2
- data/website/version-raw.js +1 -1
- data/website/version.js +1 -1
- metadata +2 -2
data/History.txt
CHANGED
data/Rakefile
CHANGED
@@ -52,7 +52,7 @@ hoe = Hoe.new(GEM_NAME, VERS) do |p|
|
|
52
52
|
|
53
53
|
# == Optional
|
54
54
|
p.changes = p.paragraphs_of("History.txt", 0..1).join("\n\n")
|
55
|
-
p.extra_deps = [['activerecord', '>= 2.
|
55
|
+
p.extra_deps = [['activerecord', '>= 2.2.0']] #An array of rubygem dependencies.
|
56
56
|
#p.spec_extras - A hash of extra values to set in the gemspec.
|
57
57
|
end
|
58
58
|
|
@@ -10,7 +10,7 @@ module CompositePrimaryKeys
|
|
10
10
|
module ClassMethods
|
11
11
|
def preload_has_and_belongs_to_many_association(records, reflection, preload_options={})
|
12
12
|
table_name = reflection.klass.quoted_table_name
|
13
|
-
id_to_record_map, ids =
|
13
|
+
id_to_record_map, ids = construct_id_map_for_composite(records)
|
14
14
|
records.each {|record| record.send(reflection.name).loaded}
|
15
15
|
options = reflection.options
|
16
16
|
|
@@ -43,7 +43,7 @@ module CompositePrimaryKeys
|
|
43
43
|
end
|
44
44
|
|
45
45
|
def preload_has_many_association(records, reflection, preload_options={})
|
46
|
-
id_to_record_map, ids =
|
46
|
+
id_to_record_map, ids = construct_id_map_for_composite(records)
|
47
47
|
records.each {|record| record.send(reflection.name).loaded}
|
48
48
|
options = reflection.options
|
49
49
|
|
@@ -219,6 +219,23 @@ module CompositePrimaryKeys
|
|
219
219
|
:order => preload_options[:order] || options[:order])
|
220
220
|
end
|
221
221
|
|
222
|
+
# Given a collection of ActiveRecord objects, constructs a Hash which maps
|
223
|
+
# the objects' IDs to the relevant objects. Returns a 2-tuple
|
224
|
+
# <tt>(id_to_record_map, ids)</tt> where +id_to_record_map+ is the Hash,
|
225
|
+
# and +ids+ is an Array of record IDs.
|
226
|
+
def construct_id_map_for_composite(records)
|
227
|
+
id_to_record_map = {}
|
228
|
+
ids = []
|
229
|
+
records.each do |record|
|
230
|
+
primary_key ||= record.class.primary_key
|
231
|
+
ids << record.id
|
232
|
+
mapped_records = (id_to_record_map[record.id.to_s] ||= [])
|
233
|
+
mapped_records << record
|
234
|
+
end
|
235
|
+
ids.uniq!
|
236
|
+
return id_to_record_map, ids
|
237
|
+
end
|
238
|
+
|
222
239
|
def full_composite_join_clause(reflection, table1, full_keys1, table2, full_keys2)
|
223
240
|
connection = reflection.active_record.connection
|
224
241
|
full_keys1 = full_keys1.split(CompositePrimaryKeys::ID_SEP) if full_keys1.is_a?(String)
|
@@ -21,7 +21,7 @@ module CompositePrimaryKeys
|
|
21
21
|
sql << " FROM #{quoted_table_name} "
|
22
22
|
sql << join_dependency.join_associations.collect{|join| join.association_join }.join
|
23
23
|
|
24
|
-
add_joins!(sql, options, scope)
|
24
|
+
add_joins!(sql, options[:joins], scope)
|
25
25
|
add_conditions!(sql, options[:conditions], scope)
|
26
26
|
add_limited_ids_condition!(sql, options, join_dependency) if !using_limitable_reflections?(join_dependency.reflections) && ((scope && scope[:limit]) || options[:limit])
|
27
27
|
|
@@ -39,7 +39,7 @@ module CompositePrimaryKeys
|
|
39
39
|
sql = "SELECT #{column_aliases(join_dependency)} FROM #{(scope && scope[:from]) || options[:from] || quoted_table_name} "
|
40
40
|
sql << join_dependency.join_associations.collect{|join| join.association_join }.join
|
41
41
|
|
42
|
-
add_joins!(sql, options, scope)
|
42
|
+
add_joins!(sql, options[:joins], scope)
|
43
43
|
add_conditions!(sql, options[:conditions], scope)
|
44
44
|
add_limited_ids_condition!(sql, options, join_dependency) if !using_limitable_reflections?(join_dependency.reflections) && options[:limit]
|
45
45
|
|
@@ -35,7 +35,8 @@ module CompositePrimaryKeys
|
|
35
35
|
join_dependency = ::ActiveRecord::Associations::ClassMethods::JoinDependency.new(self, merged_includes, options[:joins])
|
36
36
|
sql << join_dependency.join_associations.collect{|join| join.association_join }.join
|
37
37
|
end
|
38
|
-
|
38
|
+
|
39
|
+
add_joins!(sql, options[:joins], scope)
|
39
40
|
add_conditions!(sql, options[:conditions], scope)
|
40
41
|
add_limited_ids_condition!(sql, options, join_dependency) if \
|
41
42
|
join_dependency &&
|
data/tmp/test.db
CHANGED
Binary file
|
data/website/index.html
CHANGED
@@ -33,10 +33,10 @@
|
|
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">
|
36
|
+
<a href="http://rubyforge.org/projects/compositekeys" class="numbers">2.2.0</a>
|
37
37
|
</div>
|
38
|
-
<h1
|
39
|
-
<h1
|
38
|
+
<h1>→ Ruby on Rails</h1>
|
39
|
+
<h1>→ ActiveRecords</h1>
|
40
40
|
<h2>What</h2>
|
41
41
|
<p>Ruby on Rails does not support composite primary keys. This free software is an extension <br />
|
42
42
|
to the database layer of Rails – <a href="http://wiki.rubyonrails.com/rails/pages/ActiveRecord">ActiveRecords</a> – to support composite primary keys as transparently as possible.</p>
|
@@ -183,7 +183,7 @@ other stories and things.</p>
|
|
183
183
|
<h2>Contact</h2>
|
184
184
|
<p>Comments are welcome. Send an email to <a href="mailto:drnicwilliams@gmail.com">Dr Nic Williams</a>.</p>
|
185
185
|
<p class="coda">
|
186
|
-
<a href="mailto:drnicwilliams@gmail.com">Dr Nic</a>,
|
186
|
+
<a href="mailto:drnicwilliams@gmail.com">Dr Nic</a>, 29th October 2008<br>
|
187
187
|
Theme extended from <a href="http://rb2js.rubyforge.org/">Paul Battley</a>
|
188
188
|
</p>
|
189
189
|
</div>
|
data/website/index.txt
CHANGED
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:
|
4
|
+
version: 2.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dr Nic Williams
|
@@ -20,7 +20,7 @@ dependencies:
|
|
20
20
|
requirements:
|
21
21
|
- - ">="
|
22
22
|
- !ruby/object:Gem::Version
|
23
|
-
version: 2.
|
23
|
+
version: 2.2.0
|
24
24
|
version:
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: hoe
|