[Dbix-class] BUG? Unable to resolve relationship

Ovid publiustemp-dbic at yahoo.com
Fri Dec 11 15:53:28 GMT 2009


(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




More information about the DBIx-Class mailing list