[Dbix-class] Question about join and relationship exploring
Tiziano
tiziano at e-tip.net
Tue Apr 29 14:37:44 BST 2008
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Hi all,
I'm developing an software based on catalyst.
this is the code generating the query:
my $resultset = $c->model('Dbs::Contacts::Contacts')->search({
thread_id => undef,
'descs.language_id' => $c->session->{language}->{id}
}, {
cache => 1 ,
join => {'metodo' => 'descs'},
'+select' => [ 'descs.value' ],
'+as' => [ 'val' ]
});
Well, metodo is a relation that contains various contact medium (
phone call, e-mail etc...)
Next thing is to push the row value in an stashed array that will be
returned by catalyst view json to the client
This is the code:
while (my $riga = $resultset->next){
push @data, { thread_id => $riga->id , sense => $riga->sense,
subject => $riga->subject,body => $riga->corpo, date =>
DateTime->now()->ymd('/'), mezzo => $riga->get_column('val') };
mezzo is the localized description for the contact medium.
this table has a threadid field that is referencing to contact table
this foreign key is identified by this relation
__PACKAGE__->has_many('subthreads','SiteDbs::Contacts::Contatti',{
'foreign.thread_id' => 'self.id' });
well, now i explore the relation and push the son for this contact
using the relationship
my $tmp = $riga->subthreads_rs;
while (my $son = $tmp->next ){
my @columns = $son->get_columns();
push @data, { thread_id => $son->thread_id , sense =>
$son->sense , subject => $son->subject, body => $son->corpo, date =>
DateTime->now()->ymd('/') , mezzo => ?? };
}
In this case get_columns('val') isn't available.
There is any way to join the relation even when using the relationship
to collect the data ?
or is better to do a new query in this way ?
my $resultset = $c->model('Dbs::Contacts::Contacts')->search({
thread_id => undef,
'descs.language_id' => $c->session->{language}->{id}
}, {
cache => 1 ,
join => {'metodo' => 'descs'},
'+select' => [ 'descs.value' ],
'+as' => [ 'val' ]
});
while (my $riga = $resultset->next){
my $columns = $riga->get_column('val');
push @data, { thread_id => $riga->id , sense => $riga->sense,
subject => $riga->subject,body => $riga->corpo, date =>
DateTime->now()->ymd('/'), mezzo => $riga->get_column('val') };
my $resultset2 = $c->model('Dbs::Contacts::Contacts')->search({
thread_id => $riga->id ,
'descs.language_id' => $c->session->{language}->{id}
}, {
cache => 1 ,
join => {'metodo' => 'descs'},
'+select' => [ 'descs.value' ],
'+as' => [ 'val' ]
});
}
}
Thanks in advance
Tiziano
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
iD8DBQFIFySokmDwOaCmsBkRApiVAJ9vEqaJXyc5ABd8IOnzO+OYghDEjwCgmMyx
8q1P18NdshvD6rIfQUqv2o4=
=bOX+
-----END PGP SIGNATURE-----
More information about the DBIx-Class
mailing list