[Catalyst] Doing work inside the DBIx::Class model
Zbigniew Lukasiak
zzbbyy at gmail.com
Thu Feb 21 10:52:27 GMT 2008
On Thu, Feb 21, 2008 at 9:17 AM, Peter Sørensen <maspsr at sdu.dk> wrote:
>
> >He meant result_source:
> >http://cpan.uwinnipeg.ca/htdocs/DBIx-Class/DBIx/Class/ResultSet.html#result_source
> >
> >But this is not all and it is something that begs for a FAQ entry - I always forget how to do it. The important thing is how to add new >>>methods to the ResultSet:
> >
> >package ArchivedBooks;
> > use base qw/DBIx::Class/;
> > __PACKAGE__->table('books_archive');
> > __PACKAGE__->source_name('Books');
> > __PACKAGE__->resultset_class('ArchivedBooks::ResultSet');
> >
> >package ArchivedBooks::ResultSet;
> >use strict;
> >use warnings;
> >
> >use base qw( DBIx::Class::ResultSet );
> >
> >sub advanced_search {
> > my ( $self, $params, $attrs ) = @_;
> >
> >$self now is a ResultSet - so you can use methods on it.
> ......................
>
>
> I have a similar problem want - to add some custom methods to the model. I've read
> your references but still - I can't get this thing to work.
>
> I have generated the model using Catalyst and get the following layout:
>
> LogParser.pm
> LogParser
> |
> |________Components.pm
> |________Connectinfo.pm
> |________Logtype.pm
>
> and if I take a look into Components it looks like:
>
> package LogParser::Schema::LogParserDB::Components;
>
> use strict;
> use warnings;
>
> use base 'DBIx::Class';
>
> __PACKAGE__->load_components("Core");
> __PACKAGE__->table("components");
> __PACKAGE__->add_columns(
> "id",
> { data_type => "INT", default_value => undef, is_nullable => 0, size => 11 },
> "component",
> { data_type => "VARCHAR", default_value => "", is_nullable => 0, size => 32 },
> "regex",
> { data_type => "TEXT", default_value => "", is_nullable => 0, size => 65535 },
> "nvars",
> { data_type => "INT", default_value => 1, is_nullable => 0, size => 10 },
> "varnames",
> { data_type => "VARCHAR", default_value => "", is_nullable => 0, size => 64 },
> );
> __PACKAGE__->set_primary_key("id");
>
>
> # Created by DBIx::Class::Schema::Loader v0.04004 @ 2008-02-12 17:08:38
> # DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:gkSc31rRGpYHxL8tAAd/kw
>
> # You can replace this text with custom content, and it will be preserved on regeneration
> 1;
>
> As I understand I have to add to above:
>
> __PACKAGE__->source_name('SomeName');
This looks like a mistake to me - I did not mention source_name
anywhere - I don't know what this is for.
> __PACKAGE__->resultset_class('Components::ResultSet');
> LogParser::Schema::LogParserDB::Components;ame"
And what is this?
> and create a new package with:
I usually just add this package to the same file as the source package
- in this case to Components.pm.
>
> package LogParser::Schema::LogParserDB::Components::ResultSet;
>
> use strict;
> use warnings;
>
> use base qw( DBIx::Class::ResultSet );
>
> sub advanced_search {
> my ( $self, $params, $attrs ) = @_;
> }
> 1;
>
> So I created Components/ResultSet.pm with this content.
>
> But it fails with :
>
> Couldn't instantiate component "LogParser::Model::LogParserDB", "Cannot load schema class 'LogParser::Schema::LogParserDB': Can't locate object method "source_name" via package "LogParser::Schema::LogParserDB::Components::ResultSet" at /usr/lib/perl5/site_perl/5.8.5/DBIx/Class/Schema.pm line 301.
>
> I tried to remove the line:
> __PACKAGE__->source_name('SomeName');
>
> but still same problem.
>
> As I read the docs the meaning of this is to use another name than the
> default name so why use it???
>
see above
--
Zbigniew Lukasiak
http://brudnopis.blogspot.com/
More information about the Catalyst
mailing list