Hey there,

I wonder, would someone be able to help me with a multi field key that
I'm having trouble with?

I've got three tables:

package Contact;
    use base qw/DBIx::Class/;

    __PACKAGE__->load_components(qw/ PK::Auto Core /);
    __PACKAGE__->table('contact');
    __PACKAGE__->add_columns(qw/
        contactid, owner, first_name, last_name, org_name/);
    __PACKAGE__->set_primary_key(qw/contactid owner/);
    __PACKAGE__->has_many(domains => 'Domain',
                { 'registrant' => 'contactid', 'owner' => 'owner' } );
    __PACKAGE__->belongs_to(owner => 'Owner');

package Domain;
    use base qw/DBIx::Class/;

    __PACKAGE__->load_components(qw/ PK::Auto Core /);
    __PACKAGE__->table('domain');
    __PACKAGE__->add_columns(qw/domainid domainnam owner registrant/);
    __PACKAGE__->set_primary_key('domainid');
    __PACKAGE__->belongs_to(owner => 'Owner');
    __PACKAGE__->belongs_to(registrant => 'Contact',
                { owner => 'owner', contactid => 'registrant' });
        
package Tao::DBIx::Owner;
    use base qw/DBIx::Class/;

    __PACKAGE__->load_components(qw/ PK::Auto Core /);
    __PACKAGE__->table('owner');
    __PACKAGE__->add_columns(qw/ownerid contact/);
    __PACKAGE__->set_primary_key('ownerid');
    __PACKAGE__->belongs_to(contact => 'Tao::DBIx::Contact',
            { ownerid => 'owner', contact => 'contactid' });
                

I've removed the columns which are not relevant to this query, so the
database looks a bit sparse.  Notice that the contact table has a two
column primary key.

The problem I have is with the has_many relationship in the contact
table.  Each contact can have many domains, and I want to read them.

    $contact = 1234;
    print $contact->first_name, "\n";
    my @domains = $contact->domains;
    exit;

However I get a relationship error,

    % ./test3.pl
    Kieren
    DBIx::Class::Relationship::Accessor::__ANON__(): Invalid rel cond key
        owner at ./test3.pl line 3


Could someone please hit me with a clue stick?

Joe
-- 
Josef Karthauser ([EMAIL PROTECTED])           http://www.josef-k.net/
Physics Particle Theory (student)   http://www.pact.cpes.sussex.ac.uk/
================ An eclectic mix of fact and theory. =================

Attachment: pgpQOolXuqIFR.pgp
Description: PGP signature

_______________________________________________
List: http://lists.rawmode.org/cgi-bin/mailman/listinfo/dbix-class
Wiki: http://dbix-class.shadowcatsystems.co.uk/
IRC: irc.perl.org#dbix-class
SVN: http://dev.catalyst.perl.org/repos/bast/trunk/DBIx-Class/
Searchable Archive: http://www.mail-archive.com/[email protected]/

Reply via email to