[Dbix-class] Why are these two relations different

John Napiorkowski jjn1056 at yahoo.com
Wed May 3 22:45:21 CEST 2006


I don't understand why the two 'add_relationships' in
the following behave so differently:

package Schema::Documents;

[all the normal setup for a schema]

__PACKAGE__->add_relationship(

  'root_folders_a', 
  'Schema::bookmarks',  
  {'foreign.document_id' => 'self.document_id'}, 

);

__PACKAGE__->add_relationship(

  'root_folders_b', 
  'Schema::bookmarks', 
  {'foreign.document_id' => 'self.document_id'}, 
  { where => { 'parent_id' => \"IS NULL" } }
);

sub root_folders_a
{
  my $self	= shift @_;
  return $self->related_resultset('root_folders_a');
}

sub root_folders_b
{
  my $self	= shift @_;
  return $self->related_resultset('root_folders_b');
}

my $schema = Schema->connect;
my $documents = $schema->resultset('Documents');

my $documents->root_folders_a->create({...}); #WORKS
my $documents->root_folders_b->create({...}); #DIES

The error I get for the second create is "No such
column -and".  I traced this error message to a
section of code in ResultSource.pm:

sub column_info {
  my ($self, $column) = @_;
  $self->throw_exception("No such column $column")
    unless exists $self->_columns->{$column};
[...]

Where it seems somebody tried to get info on the
'-and' clause which I guess is part of how the system
adds the constraints.  So I traced it further back to
find out who is passing column_info such dubious
information.  I found the following in ResultSet.pm:

sub new_result {
  my ($self, $values) = @_;
 [....]
  my %new = %$values;

#Right now %new is a hash of all the real columns

  my $alias = $self->{attrs}{alias};
  foreach my $key (keys %{$self->{cond}||{}}) {
    $new{$1} = $self->{cond}{$key} if ($key =~
m/^(?:\Q${alias}.\E)?([^.]+)$/);
  }

#but after the loop above it's got the '-and' and some
#other stuff.

[...]
}

I don't understand the system well enough to determine
if this area is the cause of the trouble.  This is as
far as I could get.  Now I think for consistency that
both relations should be able to call methods and such
with equal results.  Why does it care if the relation
is very simple or more complex?

Any thought or suggestions would be appreciated.

--john







__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 



More information about the Dbix-class mailing list