composite keys of different data type

19 views
Skip to first unread message

ssswdon

unread,
Jul 28, 2009, 10:01:05 AM7/28/09
to Composite Keys for ActiveRecord
Hi,

I am trying to use this gem and am having the pain of using a legacy
db. The existing primary keys are made up of a 2 columns, 1 - varchar
and 1 - tinyint. Yes you guessed it, mssql ;).

Anyways I have the following in my model
set_primary_keys :attachmentid, :seq

when I do a find
Attachment.find('a_text_key',1)

I get

RuntimeError: ["a_text_value"]: Incorrect number of primary keys for
AcordAttachment: [:AttachmentID, :Seq]
from /usr/lib/ruby/gems/1.8/gems/composite_primary_keys-2.3.2/
lib/composite_primary_keys/base.rb:273:in `find_fr
om_ids'

It looks like the easy solution would be to add id's and relation
tables but for now.

Is there a way to work with keys of different type ?

ssswdon

unread,
Jul 28, 2009, 11:29:13 AM7/28/09
to Composite Keys for ActiveRecord
Ok, I figured this one out. When using composite keys of differant
type all you have to do is create a comma delimited string of values
like this. Where these values make up the natural primary key

Attachment.find('ATT_1_1_FN7024756, 1')

Don

Lori M Olson

unread,
Jul 29, 2009, 11:18:55 AM7/29/09
to Composite Keys for ActiveRecord
The comma works, but that is mostly for use with params[:id], so you
don't have to parse your keys out of the string. You should be using
an array to pass your keys to various ActiveRecord methods when using
CPK:

Attachment.find(['a_text_key',1])

Regards, Lori
Reply all
Reply to author
Forward
0 new messages