Re: Simple newbie question on relationships

[prev] [thread] [next] [Date index for 2004/12/02]

From: Sean Davis
Subject: Re: Simple newbie question on relationships
Date: 17:58 on 02 Dec 2004
On Dec 2, 2004, at 11:04 AM, Tom Hukins wrote:

> On Thu, Dec 02, 2004 at 07:24:50AM -0500, Sean Davis wrote:
>> As the title implies, I am new to Class::DBI.  I have the following 
>> set
>> up (see below--of course, there is a base package...).  However, in a
>> minimal example, it fails.
>>
>> [holmes:~/annotation/perl/pg] sdavis% perl -MProbeDBI -e '0'
>> has_a needs a valid column at
>> /Library/Perl/5.8.1/Class/DBI/Relationship/HasA.pm line 12
>> Compilation failed in require.
>> BEGIN failed--compilation aborted.
>
> Do you have separate files defining each class?  If the code you
> posted exists in the same file, you try to define a has_a relationship
> to ProbeDBI::db before defining this class.
>
> You can either break the classes into separate files or declare
> relationships after defining each package.
>

I'm not sure that this makes a difference.  After some more reading and 
some redirection from an earlier post, the following works as I like, 
and they are all in the same file in this order.

# -------------------------------------------------------------------
package ProbeDBI::analysis;
use base 'ProbeDBI';

__PACKAGE__->table('analysis');

__PACKAGE__->sequence('analysis_analysis_id_seq');
__PACKAGE__->columns(All => qw/analysis_id db_id platform_id done_date 
program description file/);
__PACKAGE__->has_a('db_id' => 'ProbeDBI::db');
__PACKAGE__->has_a('platform_id' => 'ProbeDBI::platform');


# -------------------------------------------------------------------
package ProbeDBI::db;
use base 'ProbeDBI';

__PACKAGE__->table('db');

__PACKAGE__->sequence('db_db_id_seq');
__PACKAGE__->columns(All => qw/db_id db/);
__PACKAGE__->has_many('analyses' => 'ProbeDBI::analysis');


>> __PACKAGE__->table('db');
>>
>> __PACKAGE__->sequence('db_db_id_seq');
>> __PACKAGE__->columns(All => qw/db_id db/);
>
> Above, you don't explicitly specify your primary columns (see "Declare
> your columns" in Class::DBI's documentation).  Do you have a reason
> for not doing this?

I have a habit of making the first column in columns(ALL....) the 
column name for the primary key for the table, and it is (generally 
speaking) a serial column.  I don't think I need to define in that 
case, as CDBI assumes the first name is the primary key, unless told 
otherwise.

> I hope that helps,
> Tom

Of course, it does.  Thanks for the reply.

Sean

Simple newbie question on relationships
Sean Davis 12:24 on 02 Dec 2004

Re: Simple newbie question on relationships
William Ross 13:48 on 02 Dec 2004

Re: Simple newbie question on relationships
Tom Hukins 16:04 on 02 Dec 2004

Re: Simple newbie question on relationships
Sean Davis 17:58 on 02 Dec 2004

Re: Simple newbie question on relationships
Tom Hukins 11:21 on 03 Dec 2004

Generated at 12:00 on 04 Dec 2004 by mariachi v0.52