[Dbix-class] BUG? Unable to resolve relationship
Scott Pham (scpham)
scpham at cisco.com
Fri Dec 11 19:25:09 GMT 2009
It looks like you are using 'left' not 'LEFT' in all caps?
-----Original Message-----
From: Ovid [mailto:publiustemp-dbic at yahoo.com]
Sent: Friday, December 11, 2009 10:53 AM
To: Rob Kinyon
Cc: DBIx::Class user and developer list
Subject: Re: [Dbix-class] BUG? Unable to resolve relationship
(Apologies if this is sent twice)
--- On Fri, 11/12/09, Rob Kinyon <rob.kinyon at gmail.com> wrote:
> From: Rob Kinyon <rob.kinyon at gmail.com>
>
> Did you add the join_type => LEFT as I suggested?
Yes.
Trying to figure out the syntax. I *think* this is the correct syntax:
The::Schema::Customer->belongs_to(
"account", "The::Schema::Account",
{ "foreign.id" => "self.account_id" },
{ join_type => 'left' },
);
# The::Schema::Customer::account(): Unable to resolve relationship
# from Customer to account: column account.left not loaded from
# storage (or not passed to new() prior to insert()). Maybe you
# forgot to call ->discard_changes to get defaults from the db. at
# loader.pl line 38
So I tried this:
The::Schema::Customer->belongs_to(
"account", "The::Schema::Account",
{ join_type => 'left' },
{ "foreign.id" => "self.account_id" }
);
# The::Schema::Customer::account(): Unable to resolve relationship
# from Customer to account: column account.left not loaded from
# storage (or not passed to new() prior to insert()). Maybe you
# forgot to call ->discard_changes to get defaults from the db. at
# loader.pl line 38
And flailing:
The::Schema::Customer->belongs_to(
"account",
"The::Schema::Account",
{ join_type => 'left',
"foreign.id" => "self.account_id"
},
);
# The::Schema::Customer::account(): Invalid rel cond key join_type
# at loader.pl line 38
I can't tell from the docs which I want, but this (from DBIx::Class::Relationship) suggest that my first try might have been correct:
# in a Book class (where Author has_many Books)
__PACKAGE__->belongs_to(
author =>
'My::DBIC::Schema::Author',
'author',
{ join_type => 'left' }
);
Also, you stated that "might_have is the LEFT JOIN version of has_many." The docs say "one-to-one". Which is correct? Should I change my code from might_have to belongs_to? (As I have above)
Cheers,
Ovid
--
Buy the book - http://www.oreilly.com/catalog/perlhks/
Tech blog - http://use.perl.org/~Ovid/journal/
Twitter - http://twitter.com/OvidPerl
Official Perl 6 Wiki - http://www.perlfoundation.org/perl6
_______________________________________________
List: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class
IRC: irc.perl.org#dbix-class
SVN: http://dev.catalyst.perl.org/repos/bast/DBIx-Class/
Searchable Archive: http://www.grokbase.com/group/dbix-class@lists.scsys.co.uk
More information about the DBIx-Class
mailing list