[Catalyst] Catalyst / DBIx Class Relationship many_to_many problem

Jakub Tutaj jamz at wp.pl
Sun Feb 1 21:10:21 GMT 2009


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.




More information about the Catalyst mailing list