[Catalyst] Doing work inside the DBIx::Class model
Matt S Trout
dbix-class at trout.me.uk
Sat Feb 23 19:29:36 GMT 2008
On Thu, Feb 21, 2008 at 09:17:33AM +0100, Peter Sørensen 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');
> __PACKAGE__->resultset_class('Components::ResultSet');
> LogParser::Schema::LogParserDB::Components;ame"
> and create a new package with:
>
> package LogParser::Schema::LogParserDB::Components::ResultSet;
load_classes() is trying to use this as a result class.
Either move it or switch to load_namespaces.
Note also there's a dbix-class list and I don't see a single bit of Catalyst
code in your post, so I'd suggest you'd be better posting there.
--
Matt S Trout Need help with your Catalyst or DBIx::Class project?
Technical Director http://www.shadowcat.co.uk/catalyst/
Shadowcat Systems Ltd. Want a managed development or deployment platform?
http://chainsawblues.vox.com/ http://www.shadowcat.co.uk/servers/
More information about the Catalyst
mailing list