I am working with a DBIx :: Class database in Catalyst. My local goal is to add new many-to-many relationships between users and, say, tasks. But I need one little trick. The user may have different roles in the task (for example, “worker” or “viewer”).
So, I have a user table with these fields:
I have a task table with these fields:
And I have a user_tasks relationship table with these fields:
I created has_many from users to user_tasks , has_many from tasks to user_tasks and the corresponding many_to_many relationships between users and tasks . And this simple part works as it should.
Then, for example, I want to get a list of users, including the user role, in the task given by $ task_id:
my $users = $schema->resultset('User')->with_task_role($task_id); while (my $u = $users->next) { print "User: " . $u->name . ", role: " . $u->get_column('task_role'); }
So, how should I encode this c_task_role custom result set to get this extra field with the user task role in my query?
source share