FAQ
Hello!

I've started using Catalyst, and now I've started writing my second app
(after 1st one - MyApp from tutorial)

I've created db tables analogic to tutorial:

courses (id, name)
users (id, name, email, etc.)
course_users (course_id, user_id)

When trying to list all users from one course,
in my tt view list.tt2 I do:

[% FOREACH course IN courses %]
[% tt_users = [ ];
tt_users.push(user.name) FOREACH user = course.users %]
[% END -%]

And then I get error:

"Couldn't render template "undef error -
DBIx::Class::Relationship::ManyToMany::__ANON__(): DBI Exception:
DBD::Pg::st execute failed: ERROR: syntax error at or near "."
LINE 1: SELECT user.id, user.name, user.email, user.pass, user.role ...
^ [for Statement "SELECT user.id, user.name, user.email,
user.pass, user.role FROM course_users me JOIN users user ON ( user.id =
me.user_id ) WHERE ( me.course_id = ? )" with ParamValues: 1='1'] at
/home/jtutaj/workspace/saps/root/src/courses/list.tt2 line 29"
From message I can see there's something with many_to_many relationship, but
found nothing when comparing to working tutorial MyApp application.

My Schema relationship parts are:

Courses.pm:
__PACKAGE__->has_many(course_users => 'saps::Schema::CourseUsers',
'course_id');
__PACKAGE__->many_to_many(users => 'course_users', 'user');

Users.pm:
__PACKAGE__->has_many(course_user => 'saps::Schema::CourseUsers',
'user_id');
__PACKAGE__->many_to_many(courses => 'course_user', 'course');

CourseUsers.pm:
__PACKAGE__->belongs_to(course => 'saps::Schema::Courses', 'course_id');
__PACKAGE__->belongs_to(user => 'saps::Schema::Users', 'user_id');

I already tried getting just simple data like user.name / course.name /
course_user.user_id
and it all works fine, but when
FOREACH user = course.users
error always occurs.

Any help?

Regards
Jakub Tutaj

--
View this message in context: http://www.nabble.com/Catalyst---DBIx-Class-Relationship-many_to_many-problem-tp21775313p21775313.html
Sent from the Catalyst Web Framework mailing list archive at Nabble.com.

Search Discussions

  • Jay Shirley at Feb 1, 2009 at 10:31 pm

    On Sun, Feb 1, 2009 at 1:10 PM, Jakub Tutaj wrote:
    Hello!

    I've started using Catalyst, and now I've started writing my second app
    (after 1st one - MyApp from tutorial)

    I've created db tables analogic to tutorial:

    courses (id, name)
    users (id, name, email, etc.)
    course_users (course_id, user_id)

    When trying to list all users from one course,
    in my tt view list.tt2 I do:

    [% FOREACH course IN courses %]
    [% tt_users = [ ];
    tt_users.push(user.name) FOREACH user = course.users %]
    [% END -%]

    And then I get error:

    "Couldn't render template "undef error -
    DBIx::Class::Relationship::ManyToMany::__ANON__(): DBI Exception:
    DBD::Pg::st execute failed: ERROR: syntax error at or near "."
    LINE 1: SELECT user.id, user.name, user.email, user.pass, user.role ...
    ^ [for Statement "SELECT user.id, user.name, user.email,
    user.pass, user.role FROM course_users me JOIN users user ON ( user.id =
    me.user_id ) WHERE ( me.course_id = ? )" with ParamValues: 1='1'] at
    /home/jtutaj/workspace/saps/root/src/courses/list.tt2 line 29"
    From message I can see there's something with many_to_many relationship, but
    found nothing when comparing to working tutorial MyApp application.

    My Schema relationship parts are:

    Courses.pm:
    __PACKAGE__->has_many(course_users => 'saps::Schema::CourseUsers',
    'course_id');
    __PACKAGE__->many_to_many(users => 'course_users', 'user');

    Users.pm:
    __PACKAGE__->has_many(course_user => 'saps::Schema::CourseUsers',
    'user_id');
    __PACKAGE__->many_to_many(courses => 'course_user', 'course');

    CourseUsers.pm:
    __PACKAGE__->belongs_to(course => 'saps::Schema::Courses', 'course_id');
    __PACKAGE__->belongs_to(user => 'saps::Schema::Users', 'user_id');

    I already tried getting just simple data like user.name / course.name /
    course_user.user_id
    and it all works fine, but when
    FOREACH user = course.users
    error always occurs.

    Any help?

    Regards
    Jakub Tutaj
    This is actually a DBIx::Class issue and not Catalyst, but the answer
    to your problem is to simply enable quoting. Since 'user' is a
    reserved word, you must quote it.

    See this section in the DBIx::Class cookbook:
    http://search.cpan.org/~ash/DBIx-Class-0.08010/lib/DBIx/Class/Manual/Cookbook.pod#Setting_quoting_for_the_generated_SQL.

    -J
  • Jakub Tutaj at Feb 2, 2009 at 8:05 pm

    J. Shirley wrote:

    This is actually a DBIx::Class issue and not Catalyst, but the answer
    to your problem is to simply enable quoting. Since 'user' is a
    reserved word, you must quote it.

    See this section in the DBIx::Class cookbook:
    http://search.cpan.org/~ash/DBIx-Class-0.08010/lib/DBIx/Class/Manual/Cookbook.pod#Setting_quoting_for_the_generated_SQL.
    That works perfectly!
    A lot of thanks for fast support.

    Jakub Tutaj
    --
    View this message in context: http://www.nabble.com/Catalyst---DBIx-Class-Relationship-many_to_many-problem-tp21775313p21797190.html
    Sent from the Catalyst Web Framework mailing list archive at Nabble.com.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupcatalyst @
categoriescatalyst, perl
postedFeb 1, '09 at 9:10p
activeFeb 2, '09 at 8:05p
posts3
users2
websitecatalystframework.org
irc#catalyst

2 users in discussion

Jakub Tutaj: 2 posts Jay Shirley: 1 post

People

Translate

site design / logo © 2022 Grokbase