composite_primary_keys 1.0.0 → 1.0.1

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.
@@ -1,3 +1,7 @@
1
+ == 1.0.1 2008-06-06
2
+
3
+ * Oracle fixes
4
+
1
5
  == 1.0.0 2008-06-05
2
6
 
3
7
  * Support for Rails 2.1
@@ -21,12 +21,12 @@ module CompositePrimaryKeys
21
21
  end.join(" OR ")
22
22
 
23
23
  conditions = [where, ids].flatten
24
- joins = "INNER JOIN #{connection.quote_table_name options[:join_table]} as t0 ON #{full_composite_join_clause(reflection.klass.quoted_table_name, reflection.klass.primary_key, 't0', reflection.association_foreign_key)}"
24
+ joins = "INNER JOIN #{connection.quote_table_name options[:join_table]} t0 ON #{full_composite_join_clause(reflection.klass.quoted_table_name, reflection.klass.primary_key, 't0', reflection.association_foreign_key)}"
25
25
  parent_primary_keys = reflection.primary_key_name.to_s.split(CompositePrimaryKeys::ID_SEP).map{|k| "t0.#{k}"}
26
26
  parent_record_id = connection.concat(parent_primary_keys.zip(["','"] * (parent_primary_keys.size - 1)).flatten.compact)
27
27
  else
28
28
  conditions = ["t0.#{reflection.primary_key_name} IN (?)", ids]
29
- joins = "INNER JOIN #{connection.quote_table_name options[:join_table]} as t0 ON #{reflection.klass.quoted_table_name}.#{reflection.klass.primary_key} = t0.#{reflection.association_foreign_key}"
29
+ joins = "INNER JOIN #{connection.quote_table_name options[:join_table]} t0 ON #{reflection.klass.quoted_table_name}.#{reflection.klass.primary_key} = t0.#{reflection.association_foreign_key}"
30
30
  parent_record_id = reflection.primary_key_name
31
31
  end
32
32
 
@@ -36,10 +36,10 @@ module CompositePrimaryKeys
36
36
  :conditions => conditions,
37
37
  :include => options[:include],
38
38
  :joins => joins,
39
- :select => "#{options[:select] || table_name+'.*'}, #{parent_record_id} as _parent_record_id",
39
+ :select => "#{options[:select] || table_name+'.*'}, #{parent_record_id} as parent_record_id_",
40
40
  :order => options[:order])
41
41
 
42
- set_association_collection_records(id_to_record_map, reflection.name, associated_records, '_parent_record_id')
42
+ set_association_collection_records(id_to_record_map, reflection.name, associated_records, 'parent_record_id_')
43
43
  end
44
44
 
45
45
  def preload_has_many_association(records, reflection, preload_options={})
@@ -106,14 +106,23 @@ module CompositePrimaryKeys
106
106
  if options[:polymorphic]
107
107
  raise AssociationNotSupported, "Polymorphic joins not supported for composite keys"
108
108
  else
109
+ # I need to keep the original ids for each record (as opposed to the stringified) so
110
+ # that they get properly converted for each db so the id_map ends up looking like:
111
+ #
112
+ # { '1,2' => {:id => [1,2], :records => [...records...]}}
109
113
  id_map = {}
114
+
110
115
  records.each do |record|
111
- key = primary_key_name.map{|k| record.send(k)}.join(CompositePrimaryKeys::ID_SEP)
112
- if key
113
- mapped_records = (id_map[key.to_s] ||= [])
114
- mapped_records << record
116
+ key = primary_key_name.map{|k| record.send(k)}
117
+ key_as_string = key.join(CompositePrimaryKeys::ID_SEP)
118
+
119
+ if key_as_string
120
+ mapped_records = (id_map[key_as_string] ||= {:id => key, :records => []})
121
+ mapped_records[:records] << record
115
122
  end
116
123
  end
124
+
125
+
117
126
  klasses_and_ids = [[reflection.klass.name, id_map]]
118
127
  end
119
128
 
@@ -124,7 +133,7 @@ module CompositePrimaryKeys
124
133
 
125
134
  if(composite?)
126
135
  primary_key = klass.primary_key.to_s.split(CompositePrimaryKeys::ID_SEP)
127
- ids = id_map.keys.uniq.map {|id| id.to_s.split(CompositePrimaryKeys::ID_SEP)}
136
+ ids = id_map.keys.uniq.map {|id| id_map[id][:id]}
128
137
 
129
138
  where = (primary_key * ids.size).in_groups_of(primary_key.size).map do |keys|
130
139
  "(" + keys.map{|key| "#{table_name}.#{key} = ?"}.join(" AND ") + ")"
@@ -167,7 +176,7 @@ module CompositePrimaryKeys
167
176
  # only one row per distinct foo_id' so this where we enforce that
168
177
  next if seen_keys[associated_record_key]
169
178
  seen_keys[associated_record_key] = true
170
- mapped_records = id_to_record_map[associated_record_key]
179
+ mapped_records = id_to_record_map[associated_record_key][:records]
171
180
  mapped_records.each do |mapped_record|
172
181
  mapped_record.send("set_#{reflection_name}_target", associated_record)
173
182
  end
@@ -2,7 +2,7 @@ module CompositePrimaryKeys
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 1
4
4
  MINOR = 0
5
- TINY = 0
5
+ TINY = 1
6
6
  STRING = [MAJOR, MINOR, TINY].join('.')
7
7
  end
8
8
  end
Binary file
@@ -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.0</a>
36
+ <a href="http://rubyforge.org/projects/compositekeys" class="numbers">1.0.1</a>
37
37
  </div>
38
38
  <h1>&#x2192; Ruby on Rails</h1>
39
39
 
@@ -296,7 +296,7 @@ other stories and things.</p>
296
296
 
297
297
  <p>Comments are welcome. Send an email to <a href="mailto:drnicwilliams@gmail.com">Dr Nic Williams</a>.</p>
298
298
  <p class="coda">
299
- <a href="mailto:drnicwilliams@gmail.com">Dr Nic</a>, 5th June 2008<br>
299
+ <a href="mailto:drnicwilliams@gmail.com">Dr Nic</a>, 6th June 2008<br>
300
300
  Theme extended from <a href="http://rb2js.rubyforge.org/">Paul Battley</a>
301
301
  </p>
302
302
  </div>
@@ -1,3 +1,3 @@
1
1
  // Announcement JS file
2
- var version = "1.0.0";
2
+ var version = "1.0.1";
3
3
  MagicAnnouncement.show('compositekeys', version);
@@ -1,4 +1,4 @@
1
1
  // Version JS file
2
- var version = "1.0.0";
2
+ var version = "1.0.1";
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.0.0
4
+ version: 1.0.1
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-05 00:00:00 -05:00
12
+ date: 2008-06-06 00:00:00 -05:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency