#25 new
DaniSchumacher

Import breaks when not using default primary key

Reported by DaniSchumacher | June 17th, 2009 @ 09:04 AM

I have a model where the primary key field is NOT "id". I work on MySQL tables that have been there before me.

class Buy < ActiveRecord::Base
  set_table_name "BUY"
  set_primary_key "buy_no"
end

When I try to import an Array of new Buys i get an error :

/usr/lib/ruby/gems/1.8/gems/activerecord-2.1.2/lib/active_record/attribute_methods.rb:251:in method_missing': undefined methodbuy_no_before_type_cast' for #<Buy:0xb70739d0> (NoMethodError)

from /usr/lib/ruby/gems/1.8/gems/ar-extensions-0.9.1/lib/ar-extensions/import.rb:174:in `send'
from /usr/lib/ruby/gems/1.8/gems/ar-extensions-0.9.1/lib/ar-extensions/import.rb:174:in `import'
from /usr/lib/ruby/gems/1.8/gems/ar-extensions-0.9.1/lib/ar-extensions/import.rb:173:in `each'
from /usr/lib/ruby/gems/1.8/gems/ar-extensions-0.9.1/lib/ar-extensions/import.rb:173:in `import'
from /usr/lib/ruby/gems/1.8/gems/ar-extensions-0.9.1/lib/ar-extensions/import.rb:168:in `each'
from /usr/lib/ruby/gems/1.8/gems/ar-extensions-0.9.1/lib/ar-extensions/import.rb:168:in `import'

the methods _before_type_cast only exist for 'ordinary' attributes
what should I do ?

Comments and changes to this ticket

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.

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

Tags

Pages