[Catalyst] Problem with prefetch DBIX::Class

seasprocket at gmail.com seasprocket at gmail.com
Thu Aug 12 04:31:58 GMT 2010


I am a DBIC beginner, but here's what I have learned: Your table classes
should subclass DBIx::Class::Core (not DBIx::Class). And if you have methods
that need to be called from a ResultSet class, then you should add also
create Schema classes that subclass ResultSet.

On Wed, Aug 11, 2010 at 12:23 PM, Marc Perez <markkus.80 at gmail.com> wrote:

> 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 =3D> "INT", default_value =3D> undef, is_nullable =3D> 0, si=
ze =3D> 10
> },
> ......
> __PACKAGE__->has_many(
>  "fieldfiles",
>  "cmsDB::Fieldfiles",
>  { "foreign.file_id" =3D> "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 =3D> "INT", default_value =3D> undef, is_nullable =3D> 0, si=
ze =3D> 10
> },
>  "language_id",
>  { data_type =3D> "INT", default_value =3D> undef, is_nullable =3D> 0, si=
ze =3D> 10
> },
>  "name",
>  {
>    data_type =3D> "VARBINARY",
>    default_value =3D> undef,
>    is_nullable =3D> 1,
>    size =3D> 250,
>  },
> ........
> __PACKAGE__->set_primary_key("file_id", "language_id");
> __PACKAGE__->belongs_to("file_id", "cmsDB::Files", { file_id =3D> "file_i=
d"
> });
> __PACKAGE__->belongs_to(
>  "language_id",
>  "cmsDB::Languages",
>  { language_id =3D> "language_id" },
> );
>
>
> I'm doing the next query:
> my $files =3D $catVar->model('cmsDB::Files')->search(
>                        {
>                                'me.cmsobj_id' =3D> $this->cmsobj_id,
>                                -or =3D> [mime_type =3D> 'image/jpeg',mime=
_type
> =3D>
> 'image/gif',mime_type =3D> 'image/png'],
>                                'fieldfiles.language_id' =3D> $langId
>                        },
>                        {
>                join =3D> 'fieldfiles',
>                prefetch =3D> 'fieldfiles'
>                        }
>                );
>
> When I try to access the fieldfiles data:
>
> while( my $file =3D $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 =3D 3;
> $Data::Dumper::Maxdepth =3D 3;
> Dumper($file->fieldfiles->name)
>
> I get this:
>
> $VAR1 =3D bless( { '_source_handle' =3D> bless( { 'source_moniker' =3D>
> 'Fieldfiles', 'schema' =3D> bless( { 'class_mappings' =3D>
> 'HASH(0xa521c78)', 'source_registrations' =3D> 'HASH(0xa5220c8)',
> 'storage' =3D> 'DBIx::Class::Storage::DBI::mysql=3DHASH(0xa52e4b8)' },
> 'cmsDB' ) }, 'DBIx::Class::ResultSourceHandle' ), '_in_storage' =3D> 1,
> '_column_data' =3D> { 'link' =3D> '', 'language_id' =3D> '1', 'name' =3D>
> 'Jam=F3n y Queso - Botiga', 'file_id' =3D> '5', 'description' =3D> '' } },
> 'cms::Model::cmsDB::Fieldfiles' );
>
>
> Maybe Im doing something wrong...
> I would really appreciate any help.
>
> Thanks
>
> Marc P=E9rez
>
> _______________________________________________
> List: Catalyst at lists.scsys.co.uk
> Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
> Searchable archive:
> http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
> Dev site: http://dev.catalyst.perl.org/
>



-- =

Bikewise: http://www.bikewise.org
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.scsys.co.uk/pipermail/catalyst/attachments/20100811/3ebd4=
483/attachment.htm


More information about the Catalyst mailing list