Re: How to avoid $class->new($value) with inflate

[prev] [thread] [next] [Date index for 2005/03/04]

From: Ofer Nave
Subject: Re: How to avoid $class->new($value) with inflate
Date: 18:15 on 04 Mar 2005
Carl Johnstone wrote:

> Ofer Nave wrote:
>
>> If you have a foreign key, like artist_id in the album table, you 
>> want to inflate the value into an Artist object, because it's cool 
>> and convenient. What you want is for the artist_id() method to return 
>> the actual value, and the artist() method to return the object.  
>> Rather than CDBI always inflating foreign keys into objects, you 
>> should have more control.
>
>
> I'd argue that your DB schema could be better.
>
> In your album table name the column artist instead of artist_id. In 
> the artist table just name the column id.
>
That's not good schema design in my book.  This is probably a subjective 
thing (as opposed to topics governed by the Normal Forms), but the 
artist column doesn't contain an artist - it contains the ID of an 
artist.  Hence it should be named artist_id.  Just like the gender 
column contains the gender - not the ID of a gender value in another 
table.  I like to Say What I Mean in schemas as well as code.

As for the classic question of 'artist_id' vs. just 'id' for the primary 
key of the artist table... you know I've never been able to make up my 
mind on that one.  There are good arguments either way.  
'artist.artist_id' is redundant, but increases clarity in join 
statements.  But just 'id' is probably better.  For one thing, it 
decouples the column name from the table name, letting you change one 
without the other.  So I'll agree with that point.

-ofer

(message missing)

How to avoid $class->new($value) with inflate
Matija Grabnar 12:18 on 03 Mar 2005

Re: How to avoid $class->new($value) with inflate
Charles Bailey 14:45 on 03 Mar 2005

Re: How to avoid $class->new($value) with inflate
William McKee 15:17 on 03 Mar 2005

Re: How to avoid $class->new($value) with inflate
Matt S Trout 15:31 on 03 Mar 2005

Re: How to avoid $class->new($value) with inflate
William McKee 15:40 on 03 Mar 2005

Re: How to avoid $class->new($value) with inflate
Charles Bailey 16:10 on 03 Mar 2005

Re: How to avoid $class->new($value) with inflate
Perrin Harkins 16:15 on 03 Mar 2005

Re: How to avoid $class->new($value) with inflate
William McKee 16:50 on 03 Mar 2005

Re: How to avoid $class->new($value) with inflate
Perrin Harkins 17:00 on 03 Mar 2005

Re: How to avoid $class->new($value) with inflate
Charles Bailey 17:29 on 03 Mar 2005

Re: How to avoid $class->new($value) with inflate
Perrin Harkins 19:34 on 03 Mar 2005

Re: How to avoid $class->new($value) with inflate
William Ross 17:10 on 03 Mar 2005

Re: How to avoid $class->new($value) with inflate
Michael Peters 17:08 on 03 Mar 2005

Re: How to avoid $class->new($value) with inflate
Perrin Harkins 17:12 on 03 Mar 2005

Re: How to avoid $class->new($value) with inflate
Perrin Harkins 19:49 on 03 Mar 2005

Re: How to avoid $class->new($value) with inflate
Carl Johnstone 09:56 on 04 Mar 2005

Re: How to avoid $class->new($value) with inflate
Frank Carnovale 23:19 on 03 Mar 2005

Re: How to avoid $class->new($value) with inflate
Frank Carnovale 23:44 on 06 Mar 2005

Re: How to avoid $class->new($value) with inflate
Matt S Trout 17:34 on 03 Mar 2005

Re: How to avoid $class->new($value) with inflate
Ofer Nave 18:15 on 04 Mar 2005

Generated at 20:12 on 07 Mar 2005 by mariachi v0.52