in reply to Class::DBI has_a relationships

I doubt this will fix the error, but shouldn't your Sessions_Metadata cross reference table have two primary keys?

__PACKAGE__->columns(Primary => qw/session_id username/); __PACKAGE__->columns(Others => qw/create_date expire query_id/);
Hope this helps ...

UPDATE:
Ahhh ... i see the problem now. You are not setting up your Users and Sessions classes to be able to 'have many' Sessions_Metadata. Here is how you might set up Users (untested). I am not sure how your tables really relate, so you may or may not need to do something similar in Sessions. Here goes:

__PACKAGE__->has_many( sessions => [EP::Common::DBI::Sessions_Metadata => 'id'] => 'session_id' );
You might need to explain more to us about how these tables relate to one another in order to find the solution.

jeffa

L-LL-L--L-LL-L--L-LL-L--
-R--R-RR-R--R-RR-R--R-RR
B--B--B--B--B--B--B--B--
H---H---H---H---H---H---
(the triplet paradiddle with high-hat)

Replies are listed 'Best First'.
Re: Re: Class::DBI has_a relationships
by drewbie (Chaplain) on May 19, 2004 at 03:12 UTC
    The CDBI Wiki has an entry about setting up many-to-many relationships, along with an example.

    Please contribute whatever you may learn back to the wiki so others can learn from your efforts.

Re: Re: Class::DBI has_a relationships
by CassJ (Sexton) on May 18, 2004 at 17:01 UTC
    Hi, thanks for the help. Can you explain what
    __PACKAGE__->has_many( sessions => [EP::Common::DBI::Sessions_Metadata => 'id'] => 'session_id' );
    is doing?

    According to the Class::DBI perldoc, has_many works like:
    has_many(method_to_create=>"foreign_class");
    so I thought I needed something like: __PACKAGE__->has_many(sessions_metadata=>"EP::Common::DB::Sessions::Metadata");
    in both Users and Sessions to declare that Sessions_Metadata was referencing them. But I get the same 'can't bind a ref error'.

      That (what you have) declares that a User has many Sessions::Metadata and that a Session has many Sessions::Metadata, but you also have to tell Sessions::Metadata that it references Users and Sessions as well.

      My snippet in question is specifying that a User can have many Sessions::Metadata classes, and the Users' foreign key 'session_id' references the Sessions::Metadata primary key 'id'. Now, whether or not this is the right fit for your database table relationship is the question, and since i don't know what it looks like, i can only speculate.

      jeffa

      L-LL-L--L-LL-L--L-LL-L--
      -R--R-RR-R--R-RR-R--R-RR
      B--B--B--B--B--B--B--B--
      H---H---H---H---H---H---
      (the triplet paradiddle with high-hat)
      
        OK. descriptions of tables are below.

        Both Users and Sessions are referenced by Sessions_Metadata

        Class::DBI doc says has_many is used to declare that another table is referencing us, so both Users and Sessions need a has_many(sessions_metadata)?

        I tried this in sessions:

        __PACKAGE__->has_many( sessions_metadata=>['EP::Common::DBI::Sessions_M +etadata' => 'session_id' ] => 'id' );
        (and equiv in users) which I was hoping meant that 'session_id' is an FK in Sessions_Metadata which refers to 'id': the PK in sessions.
        Still get the same error.
        have I got the wrong end of the stick?
        sessions_metadata Column | Type | Modifiers -------------+------------------------+----------- session_id | character(32) | not null username | character varying(40) | create_date | character varying(100) | expire | character varying(100) | query_id | character varying(50) | Indexes: sessions_metadata_pkey primary key btree (session_id) Foreign Key constraints: $1 FOREIGN KEY (session_id) REFERENCES sessio +ns(id) ON UPDATE NO ACTION ON DELETE NO ACTION, $2 FOREIGN KEY (username) REFERENCES users(us +ername) ON UPDATE NO ACTION ON DELETE NO ACTION sessions Column | Type | Modifiers -----------+---------------+----------- id | character(32) | not null a_session | text | Indexes: sessions_pkey primary key btree (id) users Column | Type | Modifiers --------------+------------------------+-------------------- username | character varying(40) | not null password | character varying(40) | not null salt | smallint | not null session_only | smallint | not null default 0 first_name | character varying(40) | not null last_name | character varying(40) | not null institute | character varying(255) | department | character varying(255) | address | character varying(255) | telephone | character varying(255) | email | character varying(100) | not null Indexes: users_pkey primary key btree (username)