Skip to content

Commit 879cc00

Browse files
imorlandclaude
andcommitted
fix: qualify ambiguous id column in FollowedUsersFilter (issue #47)
On PostgreSQL, whereIn/whereNotIn with an unqualified 'id' column fails with "column reference is ambiguous" when the user query has a JOIN in scope (e.g. from another extension's global scope). Qualify as 'users.id' in both branches of FollowedUsersFilter::constrain(). Also fix the test helper calls to use withQueryParams() instead of the unsupported 'queryParams' option, so the filter is actually applied. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 8eca7fb commit 879cc00

File tree

2 files changed

+8
-38
lines changed

2 files changed

+8
-38
lines changed

src/Query/FollowedUsersFilter.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,9 @@ protected function constrain(\Illuminate\Database\Eloquent\Builder $query, User
4343
$query->where(function ($query) use ($actor, $negate) {
4444
$ids = $actor->followedUsers()->pluck('users.id');
4545
if ($negate) {
46-
$query->whereNotIn('id', $ids);
46+
$query->whereNotIn('users.id', $ids);
4747
} else {
48-
$query->whereIn('id', $ids);
48+
$query->whereIn('users.id', $ids);
4949
}
5050
});
5151
}

tests/integration/api/FollowedUsersFilterTest.php

Lines changed: 6 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,6 @@
2525
* PDOException: SQLSTATE[42702]: Ambiguous column: column reference "id" is ambiguous
2626
*
2727
* The column references must be qualified as `users.id`.
28-
*
29-
* Note: SQLite (used in CI) does not raise an ambiguity error, so these tests
30-
* will appear to pass on the current (buggy) code under SQLite. They exist to:
31-
* 1. Document and lock in the correct behaviour.
32-
* 2. Fail on PostgreSQL until the fix is applied.
33-
* 3. Act as a regression guard going forward.
3428
*/
3529
class FollowedUsersFilterTest extends TestCase
3630
{
@@ -60,16 +54,8 @@ public function setUp(): void
6054
public function followeduser_filter_returns_only_followed_users()
6155
{
6256
$response = $this->send(
63-
$this->request(
64-
'GET',
65-
'/api/users',
66-
[
67-
'authenticatedAs' => 2,
68-
'queryParams' => [
69-
'filter' => ['followeduser' => '1'],
70-
],
71-
]
72-
)
57+
$this->request('GET', '/api/users', ['authenticatedAs' => 2])
58+
->withQueryParams(['filter' => ['followeduser' => '1']])
7359
);
7460

7561
$this->assertEquals(200, $response->getStatusCode());
@@ -87,16 +73,8 @@ public function followeduser_filter_returns_only_followed_users()
8773
public function negated_followeduser_filter_excludes_followed_users()
8874
{
8975
$response = $this->send(
90-
$this->request(
91-
'GET',
92-
'/api/users',
93-
[
94-
'authenticatedAs' => 2,
95-
'queryParams' => [
96-
'filter' => ['-followeduser' => '1'],
97-
],
98-
]
99-
)
76+
$this->request('GET', '/api/users', ['authenticatedAs' => 2])
77+
->withQueryParams(['filter' => ['-followeduser' => '1']])
10078
);
10179

10280
$this->assertEquals(200, $response->getStatusCode());
@@ -114,16 +92,8 @@ public function negated_followeduser_filter_excludes_followed_users()
11492
public function followeduser_filter_returns_empty_when_actor_follows_nobody()
11593
{
11694
$response = $this->send(
117-
$this->request(
118-
'GET',
119-
'/api/users',
120-
[
121-
'authenticatedAs' => 5,
122-
'queryParams' => [
123-
'filter' => ['followeduser' => '1'],
124-
],
125-
]
126-
)
95+
$this->request('GET', '/api/users', ['authenticatedAs' => 5])
96+
->withQueryParams(['filter' => ['followeduser' => '1']])
12797
);
12898

12999
$this->assertEquals(200, $response->getStatusCode());

0 commit comments

Comments
 (0)