Describe the Bug
When using a hasMany relationship field that points to a localized collection, querying documents with this relationship causes a SQLite error:
D1_ERROR: ambiguous column name: id at offset 240: SQLITE_ERROR
The generated SQL query does not qualify the id column in the WHERE clause when joining the main table with its _locales table.
Root Cause
The generated SQL:
SELECT DISTINCT "keywords"."id", "keywords_locales"."name"
FROM "keywords"
LEFT JOIN "keywords_locales" ON "keywords"."id" = "keywords_locales"."_parent_id"
WHERE id IN (1) -- NOT QUALIFIED!
Should be: WHERE "keywords"."id" IN (1)
Workaround
Remove localized: true from the target collection fields.
Related
Similar to #8455 and #8462 but different case
Related: drizzle-team/drizzle-orm#2772
### Link to the code that reproduces this issue
https://github.com/payloadcms/payload/tree/main/templates/blank
### Reproduction Steps
Reproduction Steps:
1. Create a localized collection "Keywords" with a localized "name" field
2. Create a "Pages" collection with a hasMany relationship field pointing to "keywords"
3. Run migrations and start the dev server
4. In the CMS, create a keyword (e.g., name: "Pricing", slug: "pricing")
5. Create or edit a page and assign the keyword to it
6. Try to view the page on the frontend (not in CMS admin)
7. Error occurs: "D1_ERROR: ambiguous column name: id"
### Which area(s) are affected?
db: d1-sqlite, db: sqlite
### Environment Info
```text
Payload Version: 3.71.1
Database Adapter: @payloadcms/db-d1-sqlite 3.71.1
Node.js: v20.x
Next.js: 15.x
Platform: Cloudflare Workers (D1)
Describe the Bug
When using a hasMany relationship field that points to a localized collection, querying documents with this relationship causes a SQLite error:
D1_ERROR: ambiguous column name: id at offset 240: SQLITE_ERROR
The generated SQL query does not qualify the id column in the WHERE clause when joining the main table with its _locales table.
Root Cause
The generated SQL: