Re: [CDBI] Working with tables without primary keys?

[prev] [thread] [next] [Date index for 2005/11/08]

From: Perrin Harkins
Subject: Re: [CDBI] Working with tables without primary keys?
Date: 17:08 on 08 Nov 2005
On Tue, 2005-11-08 at 10:50 -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.

I would say that's not a hack but rather the correct solution.  Multi-
column primary keys are normal in a table like this.

> my @actions = Test::Action->retrieve_all;
> 
> for (sort { $a->person_id cmp $b->person_id } @actions) {
>     print join("\t", $_->person_id, $_->action) . "\n";
> }

If you use the RetrievAll plugin, you can specify a sort field for
retrieve_all instead of doing it in perl.

> print "---\n";
> 
> my @people = Test::Person->retrieve_all;
> 
> for (sort { $a->person_id cmp $b->person_id } @people) {
>     print join("\t", $_->person_id, $_->person_name) . "\n";
> 
>     my @actions = Test::Action->search({ person_id => $_->person_id });

If you use a has_many relationship in Person, you can get it to do this
for you.  It will sort them for you too.

- Perrin


_______________________________________________
ClassDBI mailing list
ClassDBI@xxxxx.xxxxxxxxxxxxxxxx.xxx
http://lists.digitalcraftsmen.net/mailman/listinfo/classdbi

Re: [CDBI] Working with tables without primary keys?
Perrin Harkins 23:51 on 07 Nov 2005

Re: [CDBI] Working with tables without primary keys?
Perrin Harkins 17:08 on 08 Nov 2005

Re: [CDBI] Working with tables without primary keys?
Perrin Harkins 23:49 on 07 Nov 2005

Re: [CDBI] Working with tables without primary keys?
Left to My Own Devices 02:49 on 08 Nov 2005

RE: [CDBI] Working with tables without primary keys?
Mark Schoonover 03:55 on 08 Nov 2005

RE: [CDBI] Working with tables without primary keys?
Left to My Own Devices 03:12 on 08 Nov 2005

RE: [CDBI] Working with tables without primary keys?
Mark Schoonover 13:16 on 08 Nov 2005

Generated at 20:55 on 09 Nov 2005 by mariachi v0.52