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 <[email protected]> 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 => "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
>
> _______________________________________________
> List: [email protected]
> Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
> Searchable archive:
> http://www.mail-archive.com/[email protected]/
> Dev site: http://dev.catalyst.perl.org/
>



-- 
Bikewise: http://www.bikewise.org
_______________________________________________
List: [email protected]
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/[email protected]/
Dev site: http://dev.catalyst.perl.org/

Reply via email to