FAQ
I started this conversation on the Catalyst group, but it now is more
appropriate to continue on this group.

I previously used load_classes and my ResultSet classes were in the
MyApp::Schema namespace and MyApp::Schema::Demo would be the result-set
for the Demo table.

If I understand it correctly and I want to have both ResultSet and
Result classes I should use the load_namespaces which gives me the
namespaces MyApp::Schema::Result::Demo and MyApp::Schema::ResultSet::Demo

I get the following error. All my classes compile OK.

Can't locate object method "source_name" via package
"MyApp::Schema::Result::Demo" at
/usr/lib/perl5/site_perl/5.8.8/DBIx/Class/Schema.pm line 443.
Compilation failed in require at test.pl line 4.
BEGIN failed--compilation aborted at test.pl line 4.

Here is my code.

#### test.pl
use strict;
use warnings;

use MyApp::Schema;

my $schema =
MyApp::Schema->connect('DBI:mysql:host=localhost;database=vertex_icydee',
'sprint', 'secret', { AutoCommit => 1}, {quote_char => q{`}, name_sep =>
q{.}});

my $demo_rs = $schema->resultset('Demo');

my $demo = $demo_rs->create({name => 'fred', value => 1});
$demo->do_something;

1;

#####
package MyApp::Schema;

use strict;
use warnings;

use base qw(DBIx::Class::Schema);

__PACKAGE__->load_namespaces;

1;

#####
package MyApp::Schema::ResultSet::Demo;

use strict;
use warnings;

use base qw(DBIx::Class);

__PACKAGE__->load_components(qw(PK::Auto Core));
__PACKAGE__->table('demo');
__PACKAGE__->add_columns(qw(id creator owner name value state));
__PACKAGE__->set_primary_key('id');

1;

#####
package MyApp::Schema::Result::Demo;
use strict;
use warnings;

sub do_something {
my ($self) = @_;

$self->state('pending');
$self->update;
}

1;

Search Discussions

  • Marc Mims at Sep 27, 2007 at 3:57 pm

    * Ian Docherty [070927 07:30]:
    #####
    package MyApp::Schema::ResultSet::Demo;

    use strict;
    use warnings;

    use base qw(DBIx::Class);

    __PACKAGE__->load_components(qw(PK::Auto Core));
    __PACKAGE__->table('demo');
    __PACKAGE__->add_columns(qw(id creator owner name value state));
    __PACKAGE__->set_primary_key('id');

    1;
    This class is named ::ResultSet::, but it doesn't look like a ResultSet
    to me. It looks like a ResultSource.

    My ResultSets look like:

    package MyApp::Schema::ResultSet::Demo;
    use base qw(DBIx::Class::ResultSet);

    sub foo {

    I have a Result class for every table, but just a few ResultSet
    classes.

    #####
    package MyApp::Schema::Result::Demo;
    use strict;
    use warnings;

    sub do_something {
    my ($self) = @_;

    $self->state('pending');
    $self->update;
    }

    1;
  • Jason Gottshall at Sep 27, 2007 at 4:51 pm

    Ian Docherty wrote:
    I get the following error. All my classes compile OK.

    Can't locate object method "source_name" via package
    "MyApp::Schema::Result::Demo" at
    /usr/lib/perl5/site_perl/5.8.8/DBIx/Class/Schema.pm line 443.
    Compilation failed in require at test.pl line 4.
    BEGIN failed--compilation aborted at test.pl line 4. [snip]
    package MyApp::Schema::ResultSet::Demo;

    use strict;
    use warnings;

    use base qw(DBIx::Class);

    __PACKAGE__->load_components(qw(PK::Auto Core));
    __PACKAGE__->table('demo');
    __PACKAGE__->add_columns(qw(id creator owner name value state));
    __PACKAGE__->set_primary_key('id');

    1;

    #####
    package MyApp::Schema::Result::Demo;
    use strict;
    use warnings;

    sub do_something {
    my ($self) = @_;

    $self->state('pending');
    $self->update;
    }

    1;
    Your ResultSet and Result classes are reversed. The "Result" is also
    known as the "source", and describes the table and its relationships;
    it's also where you can put custom methods for individual rows that you
    retrieve. The "ResultSet" is where you put methods for operating on
    queries as a whole.

    HTH,
    Jason
  • Matt S Trout at Sep 27, 2007 at 9:45 pm

    On Thu, Sep 27, 2007 at 11:51:58AM -0400, Jason Gottshall wrote:
    Ian Docherty wrote:
    I get the following error. All my classes compile OK.

    Can't locate object method "source_name" via package
    "MyApp::Schema::Result::Demo" at
    /usr/lib/perl5/site_perl/5.8.8/DBIx/Class/Schema.pm line 443.
    Compilation failed in require at test.pl line 4.
    BEGIN failed--compilation aborted at test.pl line 4. [snip]
    package MyApp::Schema::ResultSet::Demo;

    use strict;
    use warnings;

    use base qw(DBIx::Class);

    __PACKAGE__->load_components(qw(PK::Auto Core));
    __PACKAGE__->table('demo');
    __PACKAGE__->add_columns(qw(id creator owner name value state));
    __PACKAGE__->set_primary_key('id');

    1;

    #####
    package MyApp::Schema::Result::Demo;
    use strict;
    use warnings;

    sub do_something {
    my ($self) = @_;

    $self->state('pending');
    $self->update;
    }

    1;
    Your ResultSet and Result classes are reversed. The "Result" is also
    known as the "source", and describes the table and its relationships;
    it's also where you can put custom methods for individual rows that you
    retrieve. The "ResultSet" is where you put methods for operating on
    queries as a whole.
    Close. The Result class has a 'result_source_instance' class data entry
    that's registered with the schema when it's loaded; this object is a
    ResultSource and represents the table.

    Things like add_columns, set_primary_key etc. both create methods on the
    result class (accessors etc.) and add the relevant information to the
    ResultSource (table) object.

    --
    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/

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupdbix-class @
categoriesperl, catalyst
postedSep 27, '07 at 3:13p
activeSep 27, '07 at 9:45p
posts4
users4
websitedbix-class.org
irc#dbix-class

People

Translate

site design / logo © 2021 Grokbase