Answer the question
In order to leave comments, you need to log in
How to write a request in DBIx::class to get information on all known users who have commented on their posts at least once?
I have 3 tables:
__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');
Answer the question
In order to leave comments, you need to log in
This is how { 'user_id' => 'post.author' }
field names cannot be compared. DBIC in this case considers that data is on the right, generates a condition user_id = ?
and tries to substitute text for comparison with a numeric field.
The correct comparison should look like this: { 'me.user_id' => { -ident => 'post.author' } }
.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question