FAQ
Hi,

I am new to Catalyst and so working my way through the tutorial.
Everything has been working fine until i reached the "A STATIC
DATABASE MODEL WITH DBIx::Class" section of the MoreCatalystBasics
tutorial.

After generating the static schema files and adding the relationships
as directed, running the test server causes this error:

mrc1-181:MyApp adam$ script/myapp_server.pl
Couldn't instantiate component "MyApp::Model::DB", "Cannot load schema
class 'MyApp::Schema': DBIx::Class::Schema::throw_exception():
DBIx::Class::Row::throw_exception(): Can't locate MyApp/Schema/
Authors.pm in @INC (@INC contains: /Library/WebServer/Documents/
Catalyst/MyApp/script/../lib /Library/Frameworks/R.framework/Resources/
library/RSPerl/perl/darwin-thread-multi-2level /usr/local/install/
Ensembl/ensembl/modules/ /usr/local/install/Ensembl/ensembl-compara/
modules/ /usr/local/lib/perl5/5.8.9/darwin-thread-multi-2level /usr/
local/lib/perl5/5.8.9 /usr/local/lib/perl5/site_perl/5.8.9/darwin-
thread-multi-2level /usr/local/lib/perl5/site_perl/5.8.9 .) at /usr/
local/lib/perl5/site_perl/5.8.9/Class/C3/Componentised.pm line 126.
Compilation failed in require at /usr/local/lib/perl5/site_perl/5.8.9/
Class/C3/Componentised.pm line 126.
Compilation failed in require at /usr/local/lib/perl5/site_perl/5.8.9/
Catalyst/Model/DBIC/Schema.pm line 333.
at script/myapp_server.pl line 55" at script/myapp_server.pl line 55
Compilation failed in require at script/myapp_server.pl line 55.

I think the problem is that my Authors.pm, Books.pm and BookAuthors.pm
were all created in MyApp/Schema/Result/ rather than MyApp/Schema/
which is what the Tutorial seems to expect (as shown by the line "edit
lib/MyApp/Schema/Books.pm")

I'm not sure if this is a DBIx::Class issue or a Catalyst issue. Does
anyone know how to rectify this problem?

DBIx::Class = 0.08012
Catalyst = 5.71000

thanks for any help

adam

Search Discussions

  • Adam Witney at Mar 11, 2009 at 12:03 pm

    On 11 Mar 2009, at 11:23, Adam Witney wrote:

    Hi,

    I am new to Catalyst and so working my way through the tutorial.
    Everything has been working fine until i reached the "A STATIC
    DATABASE MODEL WITH DBIx::Class" section of the MoreCatalystBasics
    tutorial.

    After generating the static schema files and adding the
    relationships as directed, running the test server causes this error:

    mrc1-181:MyApp adam$ script/myapp_server.pl
    Couldn't instantiate component "MyApp::Model::DB", "Cannot load
    schema class 'MyApp::Schema':
    DBIx::Class::Schema::throw_exception():
    DBIx::Class::Row::throw_exception(): Can't locate MyApp/Schema/
    Authors.pm in @INC (@INC contains: /Library/WebServer/Documents/
    Catalyst/MyApp/script/../lib /Library/Frameworks/R.framework/
    Resources/library/RSPerl/perl/darwin-thread-multi-2level /usr/local/
    install/Ensembl/ensembl/modules/ /usr/local/install/Ensembl/ensembl-
    compara/modules/ /usr/local/lib/perl5/5.8.9/darwin-thread-
    multi-2level /usr/local/lib/perl5/5.8.9 /usr/local/lib/perl5/
    site_perl/5.8.9/darwin-thread-multi-2level /usr/local/lib/perl5/
    site_perl/5.8.9 .) at /usr/local/lib/perl5/site_perl/5.8.9/Class/C3/
    Componentised.pm line 126.
    Compilation failed in require at /usr/local/lib/perl5/site_perl/
    5.8.9/Class/C3/Componentised.pm line 126.
    Compilation failed in require at /usr/local/lib/perl5/site_perl/
    5.8.9/Catalyst/Model/DBIC/Schema.pm line 333.
    at script/myapp_server.pl line 55" at script/myapp_server.pl line 55
    Compilation failed in require at script/myapp_server.pl line 55.

    I think the problem is that my Authors.pm, Books.pm and
    BookAuthors.pm were all created in MyApp/Schema/Result/ rather than
    MyApp/Schema/ which is what the Tutorial seems to expect (as shown
    by the line "edit lib/MyApp/Schema/Books.pm")

    I'm not sure if this is a DBIx::Class issue or a Catalyst issue.
    Does anyone know how to rectify this problem?

    DBIx::Class = 0.08012
    Catalyst = 5.71000
    ok, so i posted too soon and have figured out the problem. I need to
    add "Result" into the relationships. Does the Tutorial need to be
    updated to reflect this? If so i have included below a quick patch
    against

    http://dev.catalyst.perl.org/repos/Catalyst/Catalyst-Manual/5.70/trunk/lib/Catalyst/Manual/Tutorial/MoreCatalystBasics.pod

    HTH

    adam


    ------------------------------------------------------------------------------------------------------------------------------------------

    1108c1108
    < class" files from the C<lib/MyApp/Schema> subdirectory. The end
    ---
    class" files from the C<lib/MyApp/Schema/Result> subdirectory. The
    end
    1129c1129
    < this step.) First edit C<lib/MyApp/Schema/Books.pm> and add the
    ---
    this step.) First edit C<lib/MyApp/Schema/Result/Books.pm> and add
    the
    1141c1141
    < __PACKAGE__->has_many(book_authors =>
    'MyApp::Schema::BookAuthors', 'book_id');
    ---
    __PACKAGE__->has_many(book_authors =>
    'MyApp::Schema::Result::BookAuthors', 'book_id');
    1181c1181
    < Then edit C<lib/MyApp/Schema/Authors.pm> and add relationship
    ---
    Then edit C<lib/MyApp/Schema/Result/Authors.pm> and add relationship
    1194c1194
    < __PACKAGE__->has_many(book_author =>
    'MyApp::Schema::BookAuthors', 'author_id');
    ---
    __PACKAGE__->has_many(book_author =>
    'MyApp::Schema::Result::BookAuthors', 'author_id');
    1205c1205
    < C<lib/MyApp/Schema/BookAuthors.pm>:
    ---
    C<lib/MyApp/Schema/Result/BookAuthors.pm>:
    1216c1216
    < __PACKAGE__->belongs_to(book => 'MyApp::Schema::Books',
    'book_id');
    ---
    __PACKAGE__->belongs_to(book => 'MyApp::Schema::Result::Books',
    'book_id');
    1223c1223
    < __PACKAGE__->belongs_to(author => 'MyApp::Schema::Authors',
    'author_id');
    ---
    __PACKAGE__->belongs_to(author =>
    'MyApp::Schema::Result::Authors', 'author_id');
  • Tomas Doran at Mar 11, 2009 at 1:10 pm

    Adam Witney wrote:
    ok, so i posted too soon and have figured out the problem. I need to
    add "Result" into the relationships. Does the Tutorial need to be
    updated to reflect this? If so i have included below a quick patch
    against

    http://dev.catalyst.perl.org/repos/Catalyst/Catalyst-Manual/5.70/trunk/lib/Catalyst/Manual/Tutorial/MoreCatalystBasics.pod
    Can you re-submit as a unified diff against the base of the
    Catalyst-Manual distribution? (this makes it much easier for someone to
    read / apply).

    But great, thank you!

    Cheers
    t0m
  • Adam Witney at Mar 11, 2009 at 1:26 pm

    On 11 Mar 2009, at 13:10, Tomas Doran wrote:

    Adam Witney wrote:
    ok, so i posted too soon and have figured out the problem. I need
    to add "Result" into the relationships. Does the Tutorial need to
    be updated to reflect this? If so i have included below a quick
    patch against

    http://dev.catalyst.perl.org/repos/Catalyst/Catalyst-Manual/5.70/trunk/lib/Catalyst/Manual/Tutorial/MoreCatalystBasics.pod
    Can you re-submit as a unified diff against the base of the Catalyst-
    Manual distribution? (this makes it much easier for someone to
    read / apply).
    is this what you mean?

    --- Catalyst-Manual-5.7018/lib/Catalyst/Manual/Tutorial/
    MoreCatalystBasics.pod 2009-03-08 23:56:26.000000000 +0000
    +++ MoreCatalystBasics.pod 2009-03-11 13:23:00.000000000 +0000
    @@ -1105,7 +1105,7 @@
    C<lib/MyApp/Model/DB.pm>. This file contains a reference to
    C<lib/MyApp/Schema.pm>, so that file is loaded next. Finally, the
    call to C<load_classes> in C<Schema.pm> will load each of the "result
    -class" files from the C<lib/MyApp/Schema> subdirectory. The end
    +class" files from the C<lib/MyApp/Schema/Result> subdirectory. The end
    result is that Catalyst will dynamically create three table-specific
    Catalyst models every time the application starts (you can see these
    three model files listed in the debug output generated when you launch
    @@ -1126,7 +1126,7 @@
    Result Class files. (Note: if you are using a database other than
    SQLite, such as PostgreSQL, then the relationship could have been
    automatically placed in the Result Class files. If so, you can skip
    -this step.) First edit C<lib/MyApp/Schema/Books.pm> and add the
    +this step.) First edit C<lib/MyApp/Schema/Result/Books.pm> and add the
    following text below the C<# You can replace this text...> comment:

    #
    @@ -1138,7 +1138,7 @@
    # 1) Name of relationship, DBIC will create accessor with
    this name
    # 2) Name of the model class referenced by this relationship
    # 3) Column name in *foreign* table (aka, foreign key in
    peer table)
    - __PACKAGE__->has_many(book_authors =>
    'MyApp::Schema::BookAuthors', 'book_id');
    + __PACKAGE__->has_many(book_authors =>
    'MyApp::Schema::Result::BookAuthors', 'book_id');

    # many_to_many():
    # args:
    @@ -1178,7 +1178,7 @@
    Note that you cannot define a C<many_to_many> relationship without
    also having the C<has_many> relationship in place.

    -Then edit C<lib/MyApp/Schema/Authors.pm> and add relationship
    +Then edit C<lib/MyApp/Schema/Result/Authors.pm> and add relationship
    information as follows (again, be careful to put in above the C<1;>
    but
    below the C<# DO NOT MODIFY THIS OR ANYTHING ABOVE!> comment):

    @@ -1191,7 +1191,7 @@
    # 1) Name of relationship, DBIC will create accessor with
    this name
    # 2) Name of the model class referenced by this relationship
    # 3) Column name in *foreign* table (aka, foreign key in
    peer table)
    - __PACKAGE__->has_many(book_author =>
    'MyApp::Schema::BookAuthors', 'author_id');
    + __PACKAGE__->has_many(book_author =>
    'MyApp::Schema::Result::BookAuthors', 'author_id');

    # many_to_many():
    # args:
    @@ -1202,7 +1202,7 @@
    __PACKAGE__->many_to_many(books => 'book_author', 'book');

    Finally, do the same for the "join table,"
    -C<lib/MyApp/Schema/BookAuthors.pm>:
    +C<lib/MyApp/Schema/Result/BookAuthors.pm>:

    #
    # Set relationships:
    @@ -1213,14 +1213,14 @@
    # 1) Name of relationship, DBIC will create accessor with
    this name
    # 2) Name of the model class referenced by this relationship
    # 3) Column name in *this* table
    - __PACKAGE__->belongs_to(book => 'MyApp::Schema::Books', 'book_id');
    + __PACKAGE__->belongs_to(book => 'MyApp::Schema::Result::Books',
    'book_id');

    # belongs_to():
    # args:
    # 1) Name of relationship, DBIC will create accessor with
    this name
    # 2) Name of the model class referenced by this relationship
    # 3) Column name in *this* table
    - __PACKAGE__->belongs_to(author => 'MyApp::Schema::Authors',
    'author_id');
    + __PACKAGE__->belongs_to(author =>
    'MyApp::Schema::Result::Authors', 'author_id');


    =head2 Run The Application
    @@ -1249,7 +1249,7 @@

    Let's add a new column to our book list page that takes advantage of
    the relationship information we manually added to our schema files in
    -the previous section. Edit C<root/src/books/list.tt2> add add the
    +the previous section. Edit C<root/src/books/list.tt2> and add the
    following code below the existing table cell that contains
    C<book.rating> (IOW, add a new table cell below the existing two
    C<E<lt>tdE<gt>> tags but above the closing C<E<lt>/trE<gt>> and
  • Jay Shirley at Mar 11, 2009 at 1:59 pm

    On Wed, Mar 11, 2009 at 6:26 AM, Adam Witney wrote:
    On 11 Mar 2009, at 13:10, Tomas Doran wrote:

    Adam Witney wrote:
    ok, so i posted too soon and have figured out the problem. I need to add
    "Result" into the relationships. Does the Tutorial need to be updated to
    reflect this? If so i have included below a quick patch against


    http://dev.catalyst.perl.org/repos/Catalyst/Catalyst-Manual/5.70/trunk/lib/Catalyst/Manual/Tutorial/MoreCatalystBasics.pod
    Can you re-submit as a unified diff against the base of the
    Catalyst-Manual distribution? (this makes it much easier for someone to read
    / apply).
    is this what you mean?

    ---
    Catalyst-Manual-5.7018/lib/Catalyst/Manual/Tutorial/MoreCatalystBasics.pod
    2009-03-08 23:56:26.000000000 +0000
    +++ MoreCatalystBasics.pod 2009-03-11 13:23:00.000000000 +0000
    @@ -1105,7 +1105,7 @@
    C<lib/MyApp/Model/DB.pm>. This file contains a reference to
    C<lib/MyApp/Schema.pm>, so that file is loaded next. Finally, the
    call to C<load_classes> in C<Schema.pm> will load each of the "result
    -class" files from the C<lib/MyApp/Schema> subdirectory. The end
    +class" files from the C<lib/MyApp/Schema/Result> subdirectory. The end
    result is that Catalyst will dynamically create three table-specific
    Catalyst models every time the application starts (you can see these
    three model files listed in the debug output generated when you launch
    @@ -1126,7 +1126,7 @@
    Result Class files. (Note: if you are using a database other than
    SQLite, such as PostgreSQL, then the relationship could have been
    automatically placed in the Result Class files. If so, you can skip
    -this step.) First edit C<lib/MyApp/Schema/Books.pm> and add the
    +this step.) First edit C<lib/MyApp/Schema/Result/Books.pm> and add the
    following text below the C<# You can replace this text...> comment:

    #
    @@ -1138,7 +1138,7 @@
    # 1) Name of relationship, DBIC will create accessor with this name
    # 2) Name of the model class referenced by this relationship
    # 3) Column name in *foreign* table (aka, foreign key in peer
    table)
    - __PACKAGE__->has_many(book_authors => 'MyApp::Schema::BookAuthors',
    'book_id');
    + __PACKAGE__->has_many(book_authors =>
    'MyApp::Schema::Result::BookAuthors', 'book_id');

    # many_to_many():
    # args:
    @@ -1178,7 +1178,7 @@
    Note that you cannot define a C<many_to_many> relationship without
    also having the C<has_many> relationship in place.

    -Then edit C<lib/MyApp/Schema/Authors.pm> and add relationship
    +Then edit C<lib/MyApp/Schema/Result/Authors.pm> and add relationship
    information as follows (again, be careful to put in above the C<1;> but
    below the C<# DO NOT MODIFY THIS OR ANYTHING ABOVE!> comment):

    @@ -1191,7 +1191,7 @@
    # 1) Name of relationship, DBIC will create accessor with this name
    # 2) Name of the model class referenced by this relationship
    # 3) Column name in *foreign* table (aka, foreign key in peer
    table)
    - __PACKAGE__->has_many(book_author => 'MyApp::Schema::BookAuthors',
    'author_id');
    + __PACKAGE__->has_many(book_author =>
    'MyApp::Schema::Result::BookAuthors', 'author_id');

    # many_to_many():
    # args:
    @@ -1202,7 +1202,7 @@
    __PACKAGE__->many_to_many(books => 'book_author', 'book');

    Finally, do the same for the "join table,"
    -C<lib/MyApp/Schema/BookAuthors.pm>:
    +C<lib/MyApp/Schema/Result/BookAuthors.pm>:

    #
    # Set relationships:
    @@ -1213,14 +1213,14 @@
    # 1) Name of relationship, DBIC will create accessor with this name
    # 2) Name of the model class referenced by this relationship
    # 3) Column name in *this* table
    - __PACKAGE__->belongs_to(book => 'MyApp::Schema::Books', 'book_id');
    + __PACKAGE__->belongs_to(book => 'MyApp::Schema::Result::Books',
    'book_id');

    # belongs_to():
    # args:
    # 1) Name of relationship, DBIC will create accessor with this name
    # 2) Name of the model class referenced by this relationship
    # 3) Column name in *this* table
    - __PACKAGE__->belongs_to(author => 'MyApp::Schema::Authors',
    'author_id');
    + __PACKAGE__->belongs_to(author => 'MyApp::Schema::Result::Authors',
    'author_id');


    =head2 Run The Application
    @@ -1249,7 +1249,7 @@

    Let's add a new column to our book list page that takes advantage of
    the relationship information we manually added to our schema files in
    -the previous section. Edit C<root/src/books/list.tt2> add add the
    +the previous section. Edit C<root/src/books/list.tt2> and add the
    following code below the existing table cell that contains
    C<book.rating> (IOW, add a new table cell below the existing two
    C<E<lt>tdE<gt>> tags but above the closing C<E<lt>/trE<gt>> and

    The line in the tutorial to create the static files is this:

    $ script/myapp_create.pl model DB DBIC::Schema MyApp::Schema
    create=static dbi:SQLite:myapp.db

    I don't see where you got 'Result' as part of the class name.

    -J
    -------------- next part --------------
    An HTML attachment was scrubbed...
    URL: http://lists.scsys.co.uk/pipermail/catalyst/attachments/20090311/dc196b28/attachment.htm
  • Adam Witney at Mar 11, 2009 at 2:21 pm

    On 11 Mar 2009, at 13:59, J. Shirley wrote:
    The line in the tutorial to create the static files is this:
    $ script/myapp_create.pl model DB DBIC::Schema MyApp::Schema
    create=static dbi:SQLite:myapp.db

    I don't see where you got 'Result' as part of the class name.
    yes thats the command I used.

    In fact I have just noticed, it is mentioned in the next tutorial
    (BasicCRUD.pod). It is now recommended to use load_namespaces to load
    the classes from lib/MyApp/Schema.pm; this looks in lib/MyApp/Schema/
    Result for the Result Class files.

    However, this was the default behaviour when I installed DBIC and
    Catalyst, so i guess the question is, is this section ("Convert to
    DBIC "load_namespaces" in BasicCRUD.pod) still needed in the Tutorial?

    thanks again

    adam
  • Kennedy Clark at Mar 11, 2009 at 4:26 pm

    On Wed, Mar 11, 2009 at 7:23 AM, Adam Witney wrote:
    Hi,

    I am new to Catalyst and so working my way through the tutorial. Everything
    has been working fine until i reached the "A STATIC DATABASE MODEL WITH
    DBIx::Class" section of the MoreCatalystBasics tutorial.

    After generating the static schema files and adding the relationships as
    directed, running the test server causes this error:

    mrc1-181:MyApp adam$ script/myapp_server.pl
    Couldn't instantiate component "MyApp::Model::DB", "Cannot load schema class
    'MyApp::Schema': DBIx::Class::Schema::throw_exception():
    DBIx::Class::Row::throw_exception(): Can't locate MyApp/Schema/Authors.pm in
    @INC (@INC contains:
    /Library/WebServer/Documents/Catalyst/MyApp/script/../lib
    /Library/Frameworks/R.framework/Resources/library/RSPerl/perl/darwin-thread-multi-2level
    /usr/local/install/Ensembl/ensembl/modules/
    /usr/local/install/Ensembl/ensembl-compara/modules/
    /usr/local/lib/perl5/5.8.9/darwin-thread-multi-2level
    /usr/local/lib/perl5/5.8.9
    /usr/local/lib/perl5/site_perl/5.8.9/darwin-thread-multi-2level
    /usr/local/lib/perl5/site_perl/5.8.9 .) at
    /usr/local/lib/perl5/site_perl/5.8.9/Class/C3/Componentised.pm line 126.
    Compilation failed in require at
    /usr/local/lib/perl5/site_perl/5.8.9/Class/C3/Componentised.pm line 126.
    Compilation failed in require at
    /usr/local/lib/perl5/site_perl/5.8.9/Catalyst/Model/DBIC/Schema.pm line 333.
    ?at script/myapp_server.pl line 55" at script/myapp_server.pl line 55
    Compilation failed in require at script/myapp_server.pl line 55.

    I think the problem is that my Authors.pm, Books.pm and BookAuthors.pm were
    all created in MyApp/Schema/Result/ rather than MyApp/Schema/ which is what
    the Tutorial seems to expect (as shown by the line "edit
    lib/MyApp/Schema/Books.pm")

    I'm not sure if this is a DBIx::Class issue or a Catalyst issue. Does anyone
    know how to rectify this problem?

    DBIx::Class = 0.08012
    Catalyst = 5.71000

    thanks for any help

    adam
    Hi,

    Yeah, the most recent version of Catalyst::Model::DBIC::Schema
    defaults to "load_namespaces", so that's the problem. The tutorial
    was written assuming the user was following along with Debian, which
    currently has an older version. I'm guessing we might want to add the
    logic to Catalyst::Helper::Model::DBIC::Schema to force it to do
    "load_classes" (maybe do that if "use_namespaces=0" is on the command
    line). But, either way, I guess the best thing to do is to have the
    user do "sudo cpan Catalyst::Model::DBIC::Schema" in
    MoreCatalystBasics.pod so we start out with "load_namespaces" right
    away vs. the current approach where we do "load_classes"
    MoreCatalystBasics.pod and migrate to "load_namespaces" in
    BasicCRUD.pod. I'll start working on those changes now (I think I can
    get an update posted to CPAN later today).

    Kennedy

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupcatalyst @
categoriescatalyst, perl
postedMar 11, '09 at 11:23a
activeMar 11, '09 at 4:26p
posts7
users4
websitecatalystframework.org
irc#catalyst

People

Translate

site design / logo © 2021 Grokbase