Engi
Engi
DTDrizzle Team
Created by Engi on 12/1/2023 in #help
Can not access relation object with 2 many relations
I'm declaring the relations of a table like this:
export const storesToStoreLocationsRelation = relations(Stores, ({ many }) => ({
storeLocations: many(StoreLocations),
}));

export const storesToLocationsRelation = relations(Stores, ({ many }) => ({
stackLocations: many(StackLocations),
}));
export const storesToStoreLocationsRelation = relations(Stores, ({ many }) => ({
storeLocations: many(StoreLocations),
}));

export const storesToLocationsRelation = relations(Stores, ({ many }) => ({
stackLocations: many(StackLocations),
}));
The reverse relation:
export const storeLocationsToStoresRelation = relations(StoreLocations, ({ one }) => ({
stores: one(Stores, {
fields: [StoreLocations.storeId],
references: [Stores.id],
}),
}));
export const storeLocationsToStoresRelation = relations(StoreLocations, ({ one }) => ({
stores: one(Stores, {
fields: [StoreLocations.storeId],
references: [Stores.id],
}),
}));
I can make this query:
const result = await db2.query.Stores.findMany({
with: {
storeLocations: {
with: {
stores: true,
},
},
},
});
const result = await db2.query.Stores.findMany({
with: {
storeLocations: {
with: {
stores: true,
},
},
},
});
but when I access result[0].storeLocations , it is not suggested and it says Property storeLocations does not exist.... But if I do console.info(result[0]) I can see storeLocations inside the object. If I remove the other many relation, then it works normally.
4 replies