У меня есть 3 таблицы:
__PACKAGE__->add_columns(
"id",
{
data_type => "integer",
is_auto_increment => 1,
is_nullable => 0,
sequence => "user_ids",
},
"name", { data_type => "char", is_nullable => 1, size => 64 },
"rating", { data_type => "char", is_nullable => 1, size => 10 },
"karma", { data_type => "char", is_nullable => 1, size => 8 },
);
__PACKAGE__->has_many(
"commenters",
"My::Schema::Result::Commenter",
{ "foreign.user_id" => "self.id" },
{ cascade_copy => 0, cascade_delete => 0 },
);
__PACKAGE__->has_many(
"posts",
"My::Schema::Result::Post",
{ "foreign.author" => "self.id" },
{ cascade_copy => 0, cascade_delete => 0 },
);
__PACKAGE__->add_columns(
"id",
{
data_type => "integer",
is_auto_increment => 1,
is_nullable => 0,
sequence => "user_ids",
},
"author",
{ data_type => "integer", is_foreign_key => 1, is_nullable => 1 },
"theme",
{ data_type => "char", is_nullable => 1, size => 100 },
"post_id",
{ data_type => "integer", is_nullable => 1 },
"rating",
{ data_type => "char", is_nullable => 1, size => 10 },
"views",
{ data_type => "char", is_nullable => 1, size => 10 },
"stars",
{ data_type => "char", is_nullable => 1, size => 10 },
);
__PACKAGE__->has_many(
"commenters",
"My::Schema::Result::Commenter",
{ "foreign.post_id" => "self.id" },
{ cascade_copy => 0, cascade_delete => 0 },
);
__PACKAGE__->belongs_to(
"author",
"My::Schema::Result::User",
{ id => "author" },
{
is_deferrable => 0,
join_type => "LEFT",
on_delete => "NO ACTION",
on_update => "NO ACTION",
},
);
__PACKAGE__->add_columns(
"user_id",
{ data_type => "integer", is_foreign_key => 1, is_nullable => 1 },
"post_id",
{ data_type => "integer", is_foreign_key => 1, is_nullable => 1 },
);
__PACKAGE__->belongs_to(
"post",
"My::Schema::Result::Post",
{ id => "post_id" },
{
is_deferrable => 0,
join_type => "LEFT",
on_delete => "NO ACTION",
on_update => "NO ACTION",
},
);
__PACKAGE__->belongs_to(
"user",
"My::Schema::Result::User",
{ id => "user_id" },
{
is_deferrable => 0,
join_type => "LEFT",
on_delete => "NO ACTION",
on_update => "NO ACTION",
},
);
Помогите мне написать запрос на получение информация по всем известным пользователям, которые хоть раз комментировали свои посты.
Пробовал:
my @commenters = $schema->resultset('Commenter')->search(
{ 'user_id' => 'post.author' }, { join => 'post' }
)->search_related('user');
Однако получаю ошибку:
DBIx::Class::Storage::DBI::_dbh_execute(): DBI Exception: DBD::Pg::st execute failed: ERROR: syntax error at or near "."
LINE 1: SELECT user.id, user.name, user.rating, user.karma FROM comm...
^ [for Statement "SELECT user.id, user.name, user.rating, user.karma FROM commenters me JOIN users user ON user.id = me.user_id WHERE ( user_id = ? )" with ParamValues: 1='post.author']