[Dbix-class] Relationship problems

Josef Karthauser joe at tao.org.uk
Fri Nov 10 23:07:05 GMT 2006


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 (joe at tao.org.uk)	       http://www.josef-k.net/
Physics Particle Theory (student)   http://www.pact.cpes.sussex.ac.uk/
================ An eclectic mix of fact and theory. =================
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 195 bytes
Desc: not available
Url : http://jules.scsys.co.uk/pipermail/dbix-class/attachments/20061110/03da2236/attachment.pgp


More information about the Dbix-class mailing list