[Catalyst] Problem with prefetch DBIX::Class
Marc Perez
markkus.80 at gmail.com
Wed Aug 11 19:23:18 GMT 2010
Hi,
My name is Marc, I'm not use to write to the list but I have a problem
which I dont know exactly how to solve.
I have this two models:
FIRST:
package cmsDB::Files;
use strict;
use warnings;
use base 'DBIx::Class';
__PACKAGE__->load_components("Core");
__PACKAGE__->table("files");
__PACKAGE__->add_columns(
"file_id",
{ data_type => "INT", default_value => undef, is_nullable => 0, size => 10 },
......
__PACKAGE__->has_many(
"fieldfiles",
"cmsDB::Fieldfiles",
{ "foreign.file_id" => "self.file_id" },
);
SECOND:
package cmsDB::Fieldfiles;
use strict;
use warnings;
use base 'DBIx::Class';
__PACKAGE__->load_components("Core");
__PACKAGE__->table("fieldfiles");
__PACKAGE__->add_columns(
"file_id",
{ data_type => "INT", default_value => undef, is_nullable => 0, size => 10 },
"language_id",
{ data_type => "INT", default_value => undef, is_nullable => 0, size => 10 },
"name",
{
data_type => "VARBINARY",
default_value => undef,
is_nullable => 1,
size => 250,
},
........
__PACKAGE__->set_primary_key("file_id", "language_id");
__PACKAGE__->belongs_to("file_id", "cmsDB::Files", { file_id => "file_id" });
__PACKAGE__->belongs_to(
"language_id",
"cmsDB::Languages",
{ language_id => "language_id" },
);
I'm doing the next query:
my $files = $catVar->model('cmsDB::Files')->search(
{
'me.cmsobj_id' => $this->cmsobj_id,
-or => [mime_type => 'image/jpeg',mime_type =>
'image/gif',mime_type => 'image/png'],
'fieldfiles.language_id' => $langId
},
{
join => 'fieldfiles',
prefetch => 'fieldfiles'
}
);
When I try to access the fieldfiles data:
while( my $file = $files->next() ) {
print($file->fieldfiles->name)
}
I get the error:
Can't locate object method "name" via package "DBIx::Class::ResultSet"
If I dump $file->fieldfiles:
$Data::Dumper::Indent = 3;
$Data::Dumper::Maxdepth = 3;
Dumper($file->fieldfiles->name)
I get this:
$VAR1 = bless( { '_source_handle' => bless( { 'source_moniker' =>
'Fieldfiles', 'schema' => bless( { 'class_mappings' =>
'HASH(0xa521c78)', 'source_registrations' => 'HASH(0xa5220c8)',
'storage' => 'DBIx::Class::Storage::DBI::mysql=HASH(0xa52e4b8)' },
'cmsDB' ) }, 'DBIx::Class::ResultSourceHandle' ), '_in_storage' => 1,
'_column_data' => { 'link' => '', 'language_id' => '1', 'name' =>
'Jamón y Queso - Botiga', 'file_id' => '5', 'description' => '' } },
'cms::Model::cmsDB::Fieldfiles' );
Maybe Im doing something wrong...
I would really appreciate any help.
Thanks
Marc Pérez
More information about the Catalyst
mailing list