CassJ has asked for the wisdom of the Perl Monks concerning the following question:
I've just started using Class::DBI and I can't quite get the hang of setting up relationships. I think I'm probably missing something obvious here, but I can't figure out what's going on. Any help would be appreciated!
I have a class Sessions_Metadata which contains foreign keys to classes Users and Sessions (see below). I have a test script which creates an instance of Sessions_Metadata and attempts the following tests:
[1] isa_ok($sessions_metadata->username,"EP::Common::DBI::Users");[2] isa_ok($sessions_metadata->session_id,"EP::Common::DBI::Sessions");
If I only run test 2, it works fine and I get:
ok 1 - The object isa EP::Common::DBI::Sessions
If I run both tests, or I run only test 1 I get an error:
Can't bind a reference (EP::Common::DBI::Sessions=HASH(0x85d1d70)) at /usr/local/lib/perl5/site_perl/5.8.1/DBIx/ContextualFetch.pm line 51,<FILE> line 47.
So, I thought the problem was with test 1 and the Users class (even though the error refers to Sessions), but if I comment out the has_a(session_id=>'EP::Common::DBI::Sessions') line in the
Sessions_Metadata class, and run test 1 I get:
ok 1 - The object isa EP::Common::DBI::Users
So, if I have both has_a definitions, the Sessions class works, but the Users class doesn't. If I only have the has_a defined for Users then the Users class works.
Can anyone see what I've done wrong?
Many thanks
Cxx
Class Definitions...
###### Users ####### package EP::Common::DBI::Users; use strict; use warnings; use base qw( EP::Common::DBI ); __PACKAGE__->table('users'); __PACKAGE__->columns(Primary => qw/username/); __PACKAGE__->columns(All => qw/password salt session_only first_name last_name institute department address telephone email/); ###### Sessions ######## package EP::Common::DBI::Sessions; use strict; use warnings; use base qw( EP::Common::DBI ); __PACKAGE__->table('sessions'); __PACKAGE__->columns(Primary => qw/id/); __PACKAGE__->columns(All => qw/a_session/); ######### Sessions_Metadata ################# package EP::Common::DBI::Sessions_Metadata; use strict; use warnings; use base qw( EP::Common::DBI ); #setup table fields __PACKAGE__->table('sessions_metadata'); __PACKAGE__->columns(Primary => qw/session_id/); __PACKAGE__->columns(Others => qw/create_date username expire query_id +/); #relations __PACKAGE__->has_a(username=>'EP::Common::DBI::Users'); __PACKAGE__->has_a(session_id=>'EP::Common::DBI::Sessions');
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Class::DBI has_a relationships
by jeffa (Bishop) on May 18, 2004 at 16:24 UTC | |
by drewbie (Chaplain) on May 19, 2004 at 03:12 UTC | |
by CassJ (Sexton) on May 18, 2004 at 17:01 UTC | |
by jeffa (Bishop) on May 18, 2004 at 17:07 UTC | |
by CassJ (Sexton) on May 18, 2004 at 17:30 UTC | |
by jeffa (Bishop) on May 18, 2004 at 17:44 UTC | |
| |
|
Re: Class::DBI has_a relationships
by perrin (Chancellor) on May 18, 2004 at 18:01 UTC | |
by CassJ (Sexton) on May 18, 2004 at 18:21 UTC | |
by drewbie (Chaplain) on May 19, 2004 at 03:02 UTC | |
by CassJ (Sexton) on May 19, 2004 at 11:36 UTC | |
by drewbie (Chaplain) on May 19, 2004 at 17:42 UTC |