[CDBI] Working with tables without primary keys?

Eamon Daly edaly at nextwavemedia.com
Tue Nov 8 17:10:16 GMT 2005


No, I know. The underlying table doesn't have a PK:

CREATE TABLE `action` (
  `person_id` int(11) NOT NULL default '0',
  `action` varchar(100) NOT NULL default '',
  KEY `person_id` (`person_id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1

so I was looking for a way to work with it under CDBI. If
there were more columns in the table, I believe I'd have to
add them all as a multi-column PK under CDBI.

____________________________________________________________
Eamon Daly



----- Original Message ----- 
From: "Matt S Trout" <dbix-class at trout.me.uk>
To: "Eamon Daly" <edaly at nextwavemedia.com>
Cc: <classdbi at svr02.digitalcraftsmen.net>
Sent: Tuesday, November 08, 2005 11:09 AM
Subject: Re: [CDBI] Working with tables without primary keys?


> On Tue, Nov 08, 2005 at 10:50:43AM -0600, Eamon Daly wrote:
>> I didn't realize that 'All' makes the left-hand item the PK.
>> My hack was to define all columns as the PK, which seems to
>> get me where I want to go. To answer the question "why?",
>> though, I would think this is a pretty common technique:
>> 
>> package Test::Action;
>> __PACKAGE__->columns(Primary => qw/person_id action/);
>> 
>> package Test::Person;
>> __PACKAGE__->columns(All => qw/person_id person_name/);
> 
> That's just a two-column primary key though - not a table without a
> primary key. The fact that you haven't yet required a column on Action
> that isn't part of the PK (e.g. time_happened) doesn't mean you don't
> have one at all.





More information about the ClassDBI mailing list