#30 new
Andy Orahood

patch to support importing tables with composite primary keys

Reported by Andy Orahood | July 28th, 2009 @ 03:18 PM

I'm using the composite primary keys plugin (http://compositekeys.rubyforge.org/) and found that I couldn't import tables with composite keys because ar-extensions didn't know how to check whether the primary key(s) were being inserted when the primary key was an array:

--- a/ar-extensions/lib/ar-extensions/import.rb
+++ b/ar-extensions/lib/ar-extensions/import.rb
@@ -185,7 +185,11 @@ class ActiveRecord::Base
       # Force the primary key col into the insert if it's not
       # on the list and we are using a sequence and stuff a nil
       # value for it into each row so the sequencer will fire later
-      if !column_names.include?(primary_key) && sequence_name && connection.prefetch_primary_key?
+      # add support for primary keys being an array rather than scalar
+      if ![primary_key].flatten.*.to_sym.to_set.subset?(column_names.*.to_sym.to_set) &&
+          sequence_name && connection.prefetch_primary_key?
          column_names << primary_key
          array_of_attributes.each { |a| a << nil }
       end

Comments and changes to this ticket

New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile ยป

ActiveRecord::Extension (aka ar-extensions) is a plugin to extend and
enhance the functionality of ActiveRecord. It starts by adding better
find support for ActiveRecord. It then adds mass data import
capabilities which are highly efficient and lastly it supports to_csv
functionality.

It also introduces a cool concept of creating easily extendable pieces
of ActiveRecord functionality, so developers don't have to understand
ActiveRecord internals or have the fear of breaking ActiveRecord
itself.

People watching this ticket

Pages