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.
@@ -1,3 +1,7 @@
1
+ == 2.2.0 2008-10-29
2
+
3
+ * Rails 2.2.0 compatibility
4
+
1
5
  == 1.1.0 2008-10-29
2
6
 
3
7
  * fixes to get cpk working for Rails 2.1.2
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.1.2']] #An array of rubygem dependencies.
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 = construct_id_map(records)
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 = construct_id_map(records)
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
- add_joins!(sql, options, scope)
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 &&
@@ -1,7 +1,7 @@
1
1
  module CompositePrimaryKeys
2
2
  module VERSION #:nodoc:
3
- MAJOR = 1
4
- MINOR = 1
3
+ MAJOR = 2
4
+ MINOR = 2
5
5
  TINY = 0
6
6
  STRING = [MAJOR, MINOR, TINY].join('.')
7
7
  end
Binary file
@@ -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">1.1.0</a>
36
+ <a href="http://rubyforge.org/projects/compositekeys" class="numbers">2.2.0</a>
37
37
  </div>
38
- <h1>&amp;#x2192; Ruby on Rails</h1>
39
- <h1>&amp;#x2192; ActiveRecords</h1>
38
+ <h1>&#8594; Ruby on Rails</h1>
39
+ <h1>&#8594; 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 &#8211; <a href="http://wiki.rubyonrails.com/rails/pages/ActiveRecord">ActiveRecords</a> &#8211; 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>, 25th October 2008<br>
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>
@@ -1,8 +1,8 @@
1
1
  h1. Composite Primary Keys
2
2
 
3
- h1. &#x2192; Ruby on Rails
3
+ h1. -> Ruby on Rails
4
4
 
5
- h1. &#x2192; ActiveRecords
5
+ h1. -> ActiveRecords
6
6
 
7
7
  h2. What
8
8
 
@@ -1,3 +1,3 @@
1
1
  // Announcement JS file
2
- var version = "1.1.0";
2
+ var version = "2.2.0";
3
3
  MagicAnnouncement.show('compositekeys', version);
@@ -1,4 +1,4 @@
1
1
  // Version JS file
2
- var version = "1.1.0";
2
+ var version = "2.2.0";
3
3
 
4
4
  document.write(" - " + version);
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.1.0
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.1.2
23
+ version: 2.2.0
24
24
  version:
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: hoe