[SP-pm] DBIx::Class - problema com colunas

Andre Carneiro andregarciacarneiro at gmail.com
Thu Jun 17 04:59:48 PDT 2010


Salve monges.


Tenho no meu esquema duas classes que representam as tabelas, conforme
abaixo:

<tabela 1>

package Scap2::DBIC::Schema::Spider_Info;

use strict;
use warnings;

use base 'DBIx::Class';

__PACKAGE__->load_components("Core");
__PACKAGE__->table("spider_info");
__PACKAGE__->add_columns(
  "spider_id",
  { data_type => "INTEGER", is_nullable => 0, size => undef },
  "spider_name",
  { data_type => "VARCHAR", is_nullable => 0, size => undef },
  "curr_process",
  { data_type => "INTEGER", is_nullable => 0, size => undef },
  "start_time",
  { data_type => "DATE", is_nullable => 0, size => undef },
  "end_time",
  { data_type => "DATE", is_nullable => 0, size => undef },
  "total_time",
  { data_type => "DATE", is_nullable => 0, size => undef },
  "parser_time",
  { data_type => "DATE", is_nullable => 0, size => undef },
  "amount",
  { data_type => "INTEGER", is_nullable => 0, size => undef },
  "amount_real",
  { data_type => "INTEGER", is_nullable => 0, size => undef },
  "status",
  { data_type => "INTEGER", is_nullable => 0, size => undef },
  "executed",
  { data_type => "INTEGER", is_nullable => 0, size => undef },

);
__PACKAGE__->set_primary_key("spider_name");
#__PACKAGE__->has_many(name => "Scap2::DBIC::Schema::Job");
__PACKAGE__->has_many(threads =>
'Scap2::DBIC::Schema::ThreadList','spider_name');


</tabela 1>


<tabela 2>
package Scap2::DBIC::Schema::ThreadList;

use strict;
use warnings;

use base 'DBIx::Class';

__PACKAGE__->load_components("Core");
__PACKAGE__->table("thread_list");
__PACKAGE__->add_columns(
  "thread_id",
  { data_type => "integer", default_value => undef, is_nullable => 0, size
=> 20 },

  "spider_name",
  { data_type => "text", default_value => undef, is_nullable => 0, size =>
100 },

  "ospid",
  { data_type => "integer", default_value => undef, is_nullable => 0, size
=> 20 },

 "syspid",
  { data_type => "integer", default_value => undef, is_nullable => 0, size
=> 20 },



);

__PACKAGE__->set_primary_key('ospid');
#__PACKAGE__->belongs_to(spider_info
=>'Scap2::DBIC::Schema::Spider_Info','spider_name');
__PACKAGE__->belongs_to(spider_info =>'Scap2::DBIC::Schema::Spider_Info' =>
 {'foreign.spider_name' => 'self.spider_name' } );


</tabela2>



Esses relacionamentos estão ok(não tá gerando erro pelo menos, e quando eu
uso DBI_TRACE o join está correto!)


A minha pesquisa utilizando essa relação, se resume no seguinte trecho de
código:


<pesquisa>

sub load_all {
my ( $self ) = @_;
my @resultset = undef;
# eval{@resultset =
$self->schema->resultset('ThreadList')->related_resultset('spider_info')->all
};
# eval{@resultset =
$self->schema->resultset('ThreadList')->search_related('spider_info',{});
eval{@resultset = $self->schema->resultset('Spider_Info')->search({},{join
=> 'threads'});
};
if($@){
print "\n\nOOOPS! Nao consegui montar a lista de threads --- $@\n\n"
}else {
my @list = ();
$self->thread_list(\@resultset);
}
        print Dumper $self->thread_list;
return $self->thread_list;
}

</pesquisa>


Minha pergunta é: Por que o DBIx::Class não inclui as colunas das duas
tabelas envolvidas no relacionamento?

SQL gerada pelo DBI_TRACE:

SELECT me.spider_id, me.spider_name, me.curr_process, me.start_time,
me.end_time, me.total_time, me.parser_time, me.amount, me.amount_real,
me.status, me.executed FROM spider_info me LEFT JOIN thread_list threads ON
threads.spider_name = me.spider_name



Thx!



-- 
André Garcia Carneiro
Analista/Desenvolvedor Perl
(11)82907780
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.pm.org/pipermail/saopaulo-pm/attachments/20100617/b5d08a9e/attachment-0001.html>


More information about the SaoPaulo-pm mailing list