Re: Need help with finding solution to CDBI bug

[prev] [thread] [next] [Date index for 2004/06/25]

From: Charles Bailey
Subject: Re: Need help with finding solution to CDBI bug
Date: 22:13 on 25 Jun 2004
--On Friday, June 25, 2004 10:06 AM -0700 Takes Tea at Half Past Three 
<nazareth-cdbi@xxxxxxxxxxx.xxx> wrote:

> Charles Bailey said:
>> I hope that helps explain the confusion to which I keep referring.
>> To summarize briefly: It seems to me that deciding id() (as a public
>> object method) should return only the SQL-level PK breaks the
>> encapsulation CDBI is trying to create, and is only in service of
>> internal use, for which case another function which is aware of CBDI
>> <-> DBI internals would suffice.
>
> I agree that id() is pretty tied to the DB (and maybe should have been
> named something like _id), but why would you expect it to not be? Where
> are you using id() that it makes sense that it returns something other
> than whatever the DB uses to identify the object?

Whenever I set up a has_a that involves a PK column.  I mean that not as a 
tautology, but as a principle.

When I'm laying out a table/class, inclusion in the PK is based on whether 
or not the attribute is necessary for uniqueness, while use of a has_a 
relationship depends on whether the data contained in the column is a 
simple scalar or has a more complex meaning.  They're (usually) orthogonal 
decisions, so I've (probably erroneously) considered in an implementation 
detail (apnd patched around it) of CDBI that it didn't support inflated PK 
columns.  I think that's why the id() discussion caught me by surprise.

> It makes sense to me that id() returns something that *identifies* an
> object, rather than something that *is* an object. I don't expect to be
> able to call $cd->id->title.

Why not?  They're different, and not mutually exclusive, properties.

> Even if I have a table like liner_notes, which might use an FK as its PK,
> I expect to write something like $liner_notes->cd->title, not
> $liner_notes->id->title;

Sure, in the straightforward case.  I've often used inflated PK columns for 
their overloading.  That way, I can say things like (contrived example)

    for my $obj in (@list) {
        print '<TR>', map("<TD>$_</TD>",$obj->id), "</TR>\n";
    }

to produce a list of objects by key, with columns overloaded as needed. 
Similarly, I use string overloading to change the representation to the 
outside world of a key value (in which case, of course, the overload
sub has to notice if the caller is the DBI, and return the DB value).

> Here's the original example from this thread:
>
>    package QT::DBI::Groups;
>    use base qw(QT::DBI);
>    __PACKAGE__->table('groups');
>    __PACKAGE__->columns(Primary => qw/grp user_id/);
>    __PACKAGE__->has_a(user_id => 'QT::DBI::Users');
>
>    package QT::DBI::Users;
>    use base qw(QT::DBI);
>    __PACKAGE__->table('users');
>    __PACKAGE__->columns(All => qw/user_id type_id reseller_id password
> credit_score ctime/);
>
>
> If you want to get the user from a $group, you call $group->user_id, not
> $group->id. If you want to get the grp, you call $group->grp.

Well, sure.  If you want to access a column by name, you call that column's 
accessor.  If you want the primary key value, you call id.  If you want to 
get it in a way that lets you get at the rest of the information user_id 
specifies, you need to say

   @pk_value = map { $group->$_ } $group->primary_columns

whereas if you want to get it in a way that looks like the DB, you use 
Tim's idiom, since QT::DBI::Groups has a multi-column PK.  Both are 
certainly possible; id(), in either sense, is just sugar for a common case.

> The case I can see that would cause a problem is when you have an
> inflated PK, and it happens to be named 'id'. Perhaps that's a case for
> renaming (via accessor_name?)?

At least.  I'd argue that, if at all possible, it's best not to name a 
column "id" if you plan to use the table for a CDBI class.

--
Regards,
Charles Bailey  < bailey _at_ newman _dot_ upenn _dot_ edu >
Newman Center at the University of Pennsylvania

(message missing)

Need help with finding solution to CDBI bug
William McKee 11:40 on 19 Jun 2004

Re: Need help with finding solution to CDBI bug
William McKee 13:19 on 21 Jun 2004

Re: Need help with finding solution to CDBI bug
Tony Bowden 14:06 on 21 Jun 2004

Re: Need help with finding solution to CDBI bug
William McKee 15:14 on 21 Jun 2004

Re: Need help with finding solution to CDBI bug
Charles Bailey 15:23 on 21 Jun 2004

Re: Need help with finding solution to CDBI bug
William McKee 17:07 on 21 Jun 2004

Re: Need help with finding solution to CDBI bug
Yuval Kogman 15:30 on 21 Jun 2004

Re: Need help with finding solution to CDBI bug
Yuval Kogman 15:37 on 21 Jun 2004

Re: Need help with finding solution to CDBI bug
Charles Bailey 16:12 on 25 Jun 2004

Re: Need help with finding solution to CDBI bug
Tony Bowden 16:33 on 25 Jun 2004

Re: Need help with finding solution to CDBI bug
Charles Bailey 21:47 on 25 Jun 2004

Re: Need help with finding solution to CDBI bug
Tony Bowden 08:34 on 26 Jun 2004

Re: Need help with finding solution to CDBI bug
Takes Tea at Half Past Three 17:06 on 25 Jun 2004

Re: Need help with finding solution to CDBI bug
Charles Bailey 22:13 on 25 Jun 2004

Re: Need help with finding solution to CDBI bug
Tony Bowden 00:10 on 26 Jun 2004

RE: Need help with finding solution to CDBI bug
robert_creager 04:34 on 03 Jul 2004

Re: Need help with finding solution to CDBI bug
William McKee 17:17 on 05 Jul 2004

Re: Need help with finding solution to CDBI bug
Robert Creager 20:57 on 05 Jul 2004

Re: Need help with finding solution to CDBI bug
Robert Creager 00:22 on 06 Jul 2004

Re: Need help with finding solution to CDBI bug
William McKee 12:50 on 06 Jul 2004

Re: Need help with finding solution to CDBI bug
William McKee 17:05 on 21 Jun 2004

Re: Need help with finding solution to CDBI bug
Yuval Kogman 17:18 on 21 Jun 2004

Re: Need help with finding solution to CDBI bug
William McKee 17:41 on 21 Jun 2004

Re: Need help with finding solution to CDBI bug
Yuval Kogman 18:04 on 21 Jun 2004

Re: Need help with finding solution to CDBI bug
William McKee 19:20 on 21 Jun 2004

Re: Need help with finding solution to CDBI bug
Yuval Kogman 20:16 on 21 Jun 2004

Re: Need help with finding solution to CDBI bug
Tony Bowden 07:34 on 22 Jun 2004

Re: Need help with finding solution to CDBI bug
Yuval Kogman 14:25 on 21 Jun 2004

Re: Need help with finding solution to CDBI bug
William McKee 20:03 on 22 Jun 2004

Re: Need help with finding solution to CDBI bug
William McKee 22:44 on 22 Jun 2004

Re: Need help with finding solution to CDBI bug
Tony Bowden 15:16 on 24 Oct 2004

Re: Need help with finding solution to CDBI bug
Charles Bailey 22:15 on 22 Jun 2004

Re: Need help with finding solution to CDBI bug
William McKee 12:33 on 23 Jun 2004

Re: Need help with finding solution to CDBI bug
Charles Bailey 17:17 on 23 Jun 2004

Re: Need help with finding solution to CDBI bug
William McKee 11:38 on 22 Jun 2004

Re: Need help with finding solution to CDBI bug
merlyn (Randal L. Schwartz) 16:10 on 22 Jun 2004

Re: Need help with finding solution to CDBI bug
William McKee 13:19 on 22 Jun 2004

Re: Need help with finding solution to CDBI bug
Charles Bailey 22:04 on 22 Jun 2004

Re: Need help with finding solution to CDBI bug
Tony Bowden 12:43 on 23 Jun 2004

Re: Need help with finding solution to CDBI bug
Yuval Kogman 19:52 on 22 Jun 2004

Re: Need help with finding solution to CDBI bug
Tony Bowden 19:56 on 23 Jun 2004

Re: Need help with finding solution to CDBI bug
William McKee 12:48 on 23 Jun 2004

Re: Need help with finding solution to CDBI bug
Charles Bailey 22:12 on 23 Jun 2004

Re: Need help with finding solution to CDBI bug
Yuval Kogman 23:30 on 22 Jun 2004

Re: Need help with finding solution to CDBI bug
Tony Bowden 07:08 on 24 Jun 2004

Re: Need help with finding solution to CDBI bug
Charles Bailey 13:53 on 24 Jun 2004

Re: Need help with finding solution to CDBI bug
Tony Bowden 14:51 on 24 Jun 2004

Re: Need help with finding solution to CDBI bug
Tony Bowden 07:12 on 24 Jun 2004

Re: Need help with finding solution to CDBI bug
Charles Bailey 13:50 on 24 Jun 2004

Re: Need help with finding solution to CDBI bug
Tony Bowden 14:55 on 24 Jun 2004

Re: Need help with finding solution to CDBI bug
Tony Bowden 16:04 on 27 Jun 2004

Re: Need help with finding solution to CDBI bug
Charles Bailey 17:53 on 27 Jun 2004

Re: Need help with finding solution to CDBI bug
William McKee 12:58 on 06 Jul 2004

Generated at 11:35 on 01 Dec 2004 by mariachi v0.52