subRows.map is not a function

I am getting a subRows.map is not a function error when adding the "with" parameter to my relational queries. here is my schema;
export const users = pgTable("users", {
id: serial("id").primaryKey(),

name: text("name"),
role: text("role").default("user"),
});

export const usersRelations = relations(users, ({ many }) => ({
parties: many(parties),
}));

export const parties = pgTable("parties", {
id: serial("id").primaryKey(),
partyName: text("party_name"),
authorId: integer("author_id"),
});

export const postsRelations = relations(parties, ({ one }) => ({
author: one(users, {
fields: [parties.authorId],
references: [users.id],
}),
}));
export const users = pgTable("users", {
id: serial("id").primaryKey(),

name: text("name"),
role: text("role").default("user"),
});

export const usersRelations = relations(users, ({ many }) => ({
parties: many(parties),
}));

export const parties = pgTable("parties", {
id: serial("id").primaryKey(),
partyName: text("party_name"),
authorId: integer("author_id"),
});

export const postsRelations = relations(parties, ({ one }) => ({
author: one(users, {
fields: [parties.authorId],
references: [users.id],
}),
}));
23 Replies
Poyraz
PoyrazOP•2y ago
cc @Dan Kochetov
const data = await db.query.users.findMany({
// @ts-ignore
where: (users, { eq }) => eq(users.id, 34),
with: {
parties: true,
},
});
const data = await db.query.users.findMany({
// @ts-ignore
where: (users, { eq }) => eq(users.id, 34),
with: {
parties: true,
},
});
errors with subRows.map is not a function
const data = await db.query.parties.findFirst({
// @ts-ignore
where: (parties, { eq }) => eq(parties.id, parseInt(id)),
with: {
author: true,
},
});
const data = await db.query.parties.findFirst({
// @ts-ignore
where: (parties, { eq }) => eq(parties.id, parseInt(id)),
with: {
author: true,
},
});
returns the party object with autor: null I use AWS Data API RDS running a postgresql11.13 engine
Dan
Dan•2y ago
will check
Poyraz
PoyrazOP•2y ago
any luck eith this cannot use relations bc of the error
Dan
Dan•2y ago
not yet, but will look into it shortly
Poyraz
PoyrazOP•2y ago
@Dan Kochetov i think i found the problem AWS-Data-api returns everything in objects such as { stringValue: "[]" }, and that is why subRows.map is not a function bc subRows is still a object doesn't drizzle handle objects returned by aws? bc now aws is only returning objects and it also makes it impossible for relations i imagine so strange thing, drizzle does handle this with old syntax like db.select().from(users), but doesnt whit relational queries
Dan
Dan•2y ago
Thanks for the investigation! I'll check it.
Poyraz
PoyrazOP•2y ago
{"data1":[{"id":{"longValue":34},"name":{"stringValue":"poyraz"}}],"data2":[{"id":34,"name":"poyraz"}]} data1 is db.query.users.findMany(), data2 is db.select().from(users)
Dan
Dan•2y ago
@poyraz could you test with [email protected]?
Poyraz
PoyrazOP•2y ago
new error: Relation author not found
{"data1":[{"id":{"longValue":34},"name":{"stringValue":"poyraz"}}],"data2":[{"id":34,"name":"poyraz"}]}
{"data1":[{"id":{"longValue":34},"name":{"stringValue":"poyraz"}}],"data2":[{"id":34,"name":"poyraz"}]}
still the same data is being returned it is not getting parsed
Dan
Dan•2y ago
checking further the actual issue was I didn't extract the field values from the Data API format for relational queries. Had to spin up an instance to test properly nomore AWS won again Should be now fixed (for real) in [email protected] @poyraz
Poyraz
PoyrazOP•2y ago
Error: Cannot find module 'drizzle-orm/version' Require stack: - /Users/poyrazbirbil/Desktop/poyrazProjects/fiesta/node_modules/.pnpm/[email protected]/node_modules/drizzle-kit/index.js at Module._resolveFilename (node:internal/modules/cjs/loader:995:15) new error cannot find drizzle-orm/version i am using sst btw i also cannot query any data from sst as it says package not found drizzle-orm maybe i did smth wrong will check it out later
Dan
Dan•2y ago
did you start seeing these errors after one of the recent updates, or are you setting up a new project?
Poyraz
PoyrazOP•2y ago
started seeing them after updating to af636c3 going back to latest drizzle version fixes the error 0.26.3 isnt throwing any erros
Dan
Dan•2y ago
did you install drizzle-orm and drizzle-kit in the monorepo root? sst uses a monorepo setup so currently you need to install drizzle in the root using -w
Poyraz
PoyrazOP•2y ago
i initiate the db through the core package do i still need to install drizzle and drizzle kit in root of monorepo downloading in root doesnt change much still same error and i dont think you need to install drizzle in root bc it was working just fine when i only had it installed in packages/core
Dan
Dan•2y ago
it might've happened because you installed another Drizzle version try removing all node_modules from the monorepo, removing drizzle-orm and drizzle-kit from package dependencies and adding them as monorepo root dependencies
Poyraz
PoyrazOP•2y ago
quick question does my drizzle.config.ts have to be in the root folder aswell
Dan
Dan•2y ago
no, but it'll be easier if it is, because drizzle-kit will detect it automatically
Poyraz
PoyrazOP•2y ago
so removed drizzle-kit and drizzle-orm from packages/core removed node modules installed using -w still same error throwing
drizzle-kit: v0.18.1

node:internal/modules/cjs/loader:995
const err = new Error(message);
^

Error: Cannot find module 'drizzle-orm/version'
Require stack:
- /Users/poyrazbirbil/Desktop/poyrazProjects/fiesta/node_modules/.pnpm/[email protected]/node_modules/drizzle-kit/index.js
at Module._resolveFilename (node:internal/modules/cjs/loader:995:15)
at Module._load (node:internal/modules/cjs/loader:841:27)
at Module.require (node:internal/modules/cjs/loader:1061:19)
at require (node:internal/modules/cjs/helpers:103:18)
at assertOrmCoreVersion (/Users/poyrazbirbil/Desktop/poyrazProjects/fiesta/node_modules/.pnpm/[email protected]/node_modules/drizzle-kit/index.js:50666:36)
at Command2.<anonymous> (/Users/poyrazbirbil/Desktop/poyrazProjects/fiesta/node_modules/.pnpm/[email protected]/node_modules/drizzle-kit/index.js:51204:3)
at Command2.listener [as _actionHandler] (/Users/poyrazbirbil/Desktop/poyrazProjects/fiesta/node_modules/.pnpm/[email protected]/node_modules/drizzle-kit/index.js:832:21)
at /Users/poyrazbirbil/Desktop/poyrazProjects/fiesta/node_modules/.pnpm/[email protected]/node_modules/drizzle-kit/index.js:1251:69
at Command2._chainOrCall (/Users/poyrazbirbil/Desktop/poyrazProjects/fiesta/node_modules/.pnpm/[email protected]/node_modules/drizzle-kit/index.js:1183:16)
at Command2._parseCommand (/Users/poyrazbirbil/Desktop/poyrazProjects/fiesta/node_modules/.pnpm/[email protected]/node_modules/drizzle-kit/index.js:1251:31) {
code: 'MODULE_NOT_FOUND',
requireStack: [
'/Users/poyrazbirbil/Desktop/poyrazProjects/fiesta/node_modules/.pnpm/[email protected]/node_modules/drizzle-kit/index.js'
]
}

Node.js v18.12.1
drizzle-kit: v0.18.1

node:internal/modules/cjs/loader:995
const err = new Error(message);
^

Error: Cannot find module 'drizzle-orm/version'
Require stack:
- /Users/poyrazbirbil/Desktop/poyrazProjects/fiesta/node_modules/.pnpm/[email protected]/node_modules/drizzle-kit/index.js
at Module._resolveFilename (node:internal/modules/cjs/loader:995:15)
at Module._load (node:internal/modules/cjs/loader:841:27)
at Module.require (node:internal/modules/cjs/loader:1061:19)
at require (node:internal/modules/cjs/helpers:103:18)
at assertOrmCoreVersion (/Users/poyrazbirbil/Desktop/poyrazProjects/fiesta/node_modules/.pnpm/[email protected]/node_modules/drizzle-kit/index.js:50666:36)
at Command2.<anonymous> (/Users/poyrazbirbil/Desktop/poyrazProjects/fiesta/node_modules/.pnpm/[email protected]/node_modules/drizzle-kit/index.js:51204:3)
at Command2.listener [as _actionHandler] (/Users/poyrazbirbil/Desktop/poyrazProjects/fiesta/node_modules/.pnpm/[email protected]/node_modules/drizzle-kit/index.js:832:21)
at /Users/poyrazbirbil/Desktop/poyrazProjects/fiesta/node_modules/.pnpm/[email protected]/node_modules/drizzle-kit/index.js:1251:69
at Command2._chainOrCall (/Users/poyrazbirbil/Desktop/poyrazProjects/fiesta/node_modules/.pnpm/[email protected]/node_modules/drizzle-kit/index.js:1183:16)
at Command2._parseCommand (/Users/poyrazbirbil/Desktop/poyrazProjects/fiesta/node_modules/.pnpm/[email protected]/node_modules/drizzle-kit/index.js:1251:31) {
code: 'MODULE_NOT_FOUND',
requireStack: [
'/Users/poyrazbirbil/Desktop/poyrazProjects/fiesta/node_modules/.pnpm/[email protected]/node_modules/drizzle-kit/index.js'
]
}

Node.js v18.12.1
full error the command i am trying to run is pnpm drizzle-kit generate:pq Any updates on this? Pretty frustrating as i cannot use relations with aws-data-api 😦
Dan
Dan•2y ago
Not a lot of ideas at the moment honestly, @Andrew Sherman might take a look, since it might be kit-related
Poyraz
PoyrazOP•2y ago
thats a bummer, @Andrew Sherman any idea what could be causing this issue?
Andrii Sherman
Andrii Sherman•2y ago
I guess the best way to help me is if you can create a new GH repo with minimal reproducible example no need for code or anything, just as simplier as possible where this issue will appear then I can just clone it and try it myself
sammccord
sammccord•11mo ago
👋 i've got an example where this pops up, but with bun and sqlite - https://github.com/sammccord/drizzle-relations-repro not sure if this is the best place to bring it up, or if it's an issue with bun and I should go there
GitHub
GitHub - sammccord/drizzle-relations-repro
Contribute to sammccord/drizzle-relations-repro development by creating an account on GitHub.
Want results from more Discord servers?
Add your server