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

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

From: Eamon Daly
Subject: Re: [CDBI] Working with tables without primary keys?
Date: 16:50 on 08 Nov 2005
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/);

...

my @actions = Test::Action->retrieve_all;

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

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 });
    print map { "\t" . $_->action . "\n" } @actions;
    print "\n";
}

This works as I'd expect:

1       Ate lunch
2       Went potty
2       Ate lunch
3       Went potty
3       Washed hands
3       Ate lunch
---
1       Tom
        Ate lunch

2       Dick
        Went potty
        Ate lunch

3       Harriet
        Went potty
        Washed hands
        Ate lunch

With person_id as the PK (using 'All'), this obviously
breaks:

1       Ate lunch
2       Went potty
2       Went potty
3       Went potty
3       Went potty
3       Went potty
---
1       Tom
        Ate lunch

2       Dick
        Went potty
        Went potty

3       Harriet
        Went potty
        Went potty
        Went potty

Of course, the Right Thing would be to add a true PK to the
action table.

____________________________________________________________
Eamon Daly



----- Original Message ----- 
From: "Perrin Harkins" <perrin@xxxx.xxx>
To: "Matt S Trout" <dbix-class@xxxxx.xx.xx>
Cc: "Eamon Daly" <edaly@xxxxxxxxxxxxx.xxx>; 
<classdbi@xxxxx.xxxxxxxxxxxxxxxx.xxx>
Sent: Monday, November 07, 2005 5:51 PM
Subject: Re: [CDBI] Working with tables without primary keys?


> On Mon, 2005-11-07 at 23:44 +0000, Matt S Trout wrote:
>> I *do* know that DBIx::Class does handle this; just build a custom base 
>> class
>> that doesn't include the PK component and you should get at least some
>> functionality
>
> What possible functionality can an O/R mapper provide when it has no way
> to individually address rows?  Something through class methods?
>
> - 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?
Eamon Daly 16:50 on 08 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