[Dbix-class] Help with relationships
Matt S Trout
dbix-class at trout.me.uk
Mon May 7 14:37:54 GMT 2007
On Fri, May 04, 2007 at 07:57:48PM -0400, Jason Kaskel wrote:
> I'm in full head banging mode now. And I'm not talking about rock!
>
> The simplified version of my problem:
>
> Variant Class:
> package JAK::Schema::Variant;
>
> # Created by DBIx::Class::Schema::Loader v0.03009 @ 2007-05-04 15:38:46
>
> use strict;
> use warnings;
>
> use base 'DBIx::Class';
>
> __PACKAGE__->load_components("PK::Auto", "Core");
> __PACKAGE__->table("variant");
> __PACKAGE__->add_columns(
> "variant_id",
> { data_type => "INT", default_value => undef, is_nullable => 0, size => 11
> },
> "game",
> { data_type => "ENUM", default_value => undef, is_nullable => 1, size =>
> 16 },
> "scenario",
> { data_type => "ENUM", default_value => undef, is_nullable => 1, size =>
> 15 },
> "goal",
> {
> data_type => "VARCHAR",
> default_value => "10,10,10,10",
> is_nullable => 0,
> size => 32,
> },
> );
> __PACKAGE__->has_many("meetings" => "JAK::Schema::Meeting");
> __PACKAGE__->set_primary_key("variant_id");
> 1;
>
> Meeting Class:
> package JAK::Schema::Meeting;
>
> # Created by DBIx::Class::Schema::Loader v0.03009 @ 2007-05-04 18:48:46
>
> use strict;
> use warnings;
>
> use base 'DBIx::Class';
>
> __PACKAGE__->load_components("PK::Auto", "Core");
> __PACKAGE__->table("meeting");
> __PACKAGE__->add_columns(
> "meeting_id",
> { data_type => "INT", default_value => undef, is_nullable => 0, size => 11
> },
> "start_time",
> {
> data_type => "DATETIME",
> default_value => "0000-00-00 00:00:00",
> is_nullable => 0,
> size => 19,
> },
> "variant",
> { data_type => "INT", default_value => 0, is_nullable => 0, size => 11 },
> "synopsis",
> {
> data_type => "TEXT",
> default_value => undef,
> is_nullable => 1,
> size => 65535,
> },
> );
> __PACKAGE__->belongs_to("variant" => "JAK::Schema::Variant");
> __PACKAGE__->set_primary_key("meeting_id");
>
> 1;
>
> Code that just won't work:
> my $rs = $JAK::schema->resultset('Meeting')->search(
> { 'meeting_id' => "1" },
> { join => 'variant' },
> );
>
> When I try to access $rs->next, it keeps telling me:
> No such relationship variant
>
> What idiotic thing am I doing wrong?
Declaring the relationship before you set the primary key, which will cause
the relationship declaration to bomb out.
--
Matt S Trout Need help with your Catalyst or DBIx::Class project?
Technical Director Want a managed development or deployment platform?
Shadowcat Systems Ltd. Contact mst (at) shadowcatsystems.co.uk for a quote
http://www.shadowcatsystems.co.uk/
More information about the Dbix-class
mailing list