Hi again, after some fight with DBIC i win in the end :P (YEAH!)
Had to rewrite some stuff, and had to forget the subselects and done the relationships well.
I know that this code don't represent the inicial question, but if i had to rewrite all again, i'm showing you the other part of my "project", where i had again other dificulties.
Next is what i've done:
DBIx::Class Schema
package DB::Esquema::Passwords;
use strict;
use warnings;
use base 'DBIx::Class';
__PACKAGE__->load_components("Core");
__PACKAGE__->table("Passwords");
__PACKAGE__->add_columns(
"pswd",
{ data_type => "INT", default_value => undef, is_nullable => 0, size => 11 },
"password",
{
data_type => "VARCHAR",
default_value => undef,
is_nullable => 1,
size => 20,
},
"utilizadorid",
{ data_type => "INT", default_value => undef, is_nullable => 1, size => 11 },
);
__PACKAGE__->set_primary_key("pswd");
__PACKAGE__->belongs_to('utilizadorid' => 'DB::Esquema::Utilizadores');
#belongs_to is not autogenerated, done by hand
Has a relationship with Utilizadores (users)
package DB::Esquema::Utilizadores;
use strict;
use warnings;
use base 'DBIx::Class';
__PACKAGE__->load_components("Core");
__PACKAGE__->table("Utilizadores");
__PACKAGE__->add_columns(
"utilizador",
{ data_type => "INT", default_value => undef, is_nullable => 0, size => 11 },
"nome",
{
data_type => "VARCHAR",
default_value => undef,
is_nullable => 1,
size => 20,
},
"mail",
{
data_type => "VARCHAR",
default_value => undef,
is_nullable => 1,
size => 30,
},
);
__PACKAGE__->set_primary_key("utilizador");
__PACKAGE__->has_one('utilizador' => 'DB::Esquema::Passwords', 'utilizadorid');
NEXT (the script to make it work)
#!/usr/bin/perl -w
use strict;
use diagnostics; #was important to understand
use lib '/var/www/projectox/lib'; #is where the schema is
use DB::Esquema; #use the Schema
system('clear'); # clear the screen
my $esquema = DB::Esquema->connect("dbi:mysql:dbname=dbswiak","root","");
$esquema->storage->debug(1);
#HAD TO USE PREFETCH
my $resultado = $esquema->resultset('Utilizadores')->search(
undef,{
prefetch => { 'utilizador' => 'utilizadorid' }
}
)->next();
The Result:
SELECT me.utilizador, me.nome, me.mail, utilizador.pswd,
utilizador.password, utilizador.utilizadorid, utilizadorid.utilizador, utilizadorid.nome, utilizadorid.mail
FROM Utilizadores me JOIN Passwords utilizador
ON utilizador.utilizadorid = me.utilizador
JOIN Utilizadores utilizadorid ON utilizadorid.utilizador = utilizador.utilizadorid:
Wasn't what i really wanted, but is the nearest, the goal is to select only the columns i want... maybe i will reach that goal