hello monks

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');

In reply to Class::DBI has_a relationships by CassJ

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.