W
Wasp•3w ago
CamBlackwood

Relation returned on findFirst but not findMany?

I am looking to make a query to return a batch of results rather than just one, but "profile" is not included in the findMany, only in the findFirst Returns profile -
export const getCreatorById: GetCreatorById<any, any> = async ({ creatorId }, context) => {
if (!context.user) {
throw new HttpError(401);
}
return context.entities.Creators.findFirst({
orderBy: { id: 'asc' },
where: {
AND: [
{
userId: +creatorId,
},
],
},
include: {
profile: true,
stats: true,
},
});
};
export const getCreatorById: GetCreatorById<any, any> = async ({ creatorId }, context) => {
if (!context.user) {
throw new HttpError(401);
}
return context.entities.Creators.findFirst({
orderBy: { id: 'asc' },
where: {
AND: [
{
userId: +creatorId,
},
],
},
include: {
profile: true,
stats: true,
},
});
};
Does not return profile:
export const getCreators: GetCreators<any, any> = async (args, context) => {
if (!context.user) {
throw new HttpError(401);
}
return context.entities.Creators.findMany({
orderBy: { id: 'asc' },
include: {
stats: true,
youtubeStats: true,
profile: true
},
});
};
export const getCreators: GetCreators<any, any> = async (args, context) => {
if (!context.user) {
throw new HttpError(401);
}
return context.entities.Creators.findMany({
orderBy: { id: 'asc' },
include: {
stats: true,
youtubeStats: true,
profile: true
},
});
};
Am I missing aything @kapa.ai ?
6 Replies
kapa.ai
kapa.ai•3w ago
Hi @CamBlackwood. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- Based on the information provided in the knowledge sources, I don't have enough specific information to directly address why the profile relation is not being returned in your findMany query while it is in the findFirst query. The behavior you're describing is not expected, as both findFirst and findMany should respect the include options similarly. However, I can offer some general advice and suggestions based on Wasp's query system: 1. First, make sure that your entity definitions in the Wasp schema correctly define the relationship between Creators and profile. The issue might be related to how the relationship is defined. 2. Double-check that the profile relation exists and is properly set up in your Prisma schema. 3. Verify that you're using the latest version of Wasp and Prisma, as there might have been updates or bug fixes related to this issue. 4. Try logging the raw result of your query to see what data is actually being returned from the database. 5. If the problem persists, you might want to try using Prisma's raw query capabilities to debug and see if the issue is with Prisma or with Wasp's handling of the query. If none of these suggestions help, you might be encountering a bug. In that case, I would recommend reaching out to the Wasp community for support. You can do this through: 1. Wasp's Discord channel 2. Filing an issue on Wasp's GitHub repository The Wasp team and community are usually very responsive and can provide more specific guidance based on your exact setup and code. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ---------------------- Sorry @CamBlackwood, I seem to be having a bit of trouble. Don't worry though, I've pinged my support and they will try to fix me up! :technologist: Perhaps try again in 15mins?
CamBlackwood
CamBlackwoodOP•3w ago
@kapa.ai here's the schema
model Creators {
id Int @id @default(autoincrement())
userId Int @unique
name String
tiktok Boolean
twitter Boolean
instagram Boolean
youtube Boolean
tiktokUsername String?
instagramUsername String?
youtubeUsername String?
niche String @default("Technology")
country String @default("United States")
tiktokFollowers Int @default(0)
twitterFollowers Int @default(0)
instagramFollowers Int @default(0)
youtubeFollowers Int @default(0)
profileSlug String?
profile CreatorProfile?
verified Boolean @default(false)
verificationSubmitted Boolean @default(false)
stats VerifiedCreatorTikTokStats?
youtubeStats VerifiedCreatorYouTubeStats?
}

model CreatorProfile {
id String @id @default(uuid())
profilePicUrl String
creatorId Int @unique
bio String?

creator Creators @relation(fields: [creatorId], references: [id], onDelete: Cascade)
}
model Creators {
id Int @id @default(autoincrement())
userId Int @unique
name String
tiktok Boolean
twitter Boolean
instagram Boolean
youtube Boolean
tiktokUsername String?
instagramUsername String?
youtubeUsername String?
niche String @default("Technology")
country String @default("United States")
tiktokFollowers Int @default(0)
twitterFollowers Int @default(0)
instagramFollowers Int @default(0)
youtubeFollowers Int @default(0)
profileSlug String?
profile CreatorProfile?
verified Boolean @default(false)
verificationSubmitted Boolean @default(false)
stats VerifiedCreatorTikTokStats?
youtubeStats VerifiedCreatorYouTubeStats?
}

model CreatorProfile {
id String @id @default(uuid())
profilePicUrl String
creatorId Int @unique
bio String?

creator Creators @relation(fields: [creatorId], references: [id], onDelete: Cascade)
}
kapa.ai
kapa.ai•3w ago
Let me check the knowledge base for you again. One moment! :books: ---------------------- Thank you for providing the schema. Based on the information you've shared, I can see that the relationship between Creators and CreatorProfile is correctly defined. The profile field in the Creators model is linked to the CreatorProfile model with a one-to-one relationship. Given this schema, both your findFirst and findMany queries should work as expected and include the profile when specified in the include option. The fact that profile is not being returned in your findMany query is unexpected behavior. Here are a few things you can try to troubleshoot this issue: 1. Make sure you're using the latest version of Wasp and Prisma. You can check this in your package.json file. 2. Try running wasp db migrate-dev to ensure your database schema is up-to-date with your Prisma schema. 3. Double-check that you're actually accessing the profile field in your client code. Sometimes, the data is there but not visible if you're not explicitly accessing it. 4. Try logging the entire result of your findMany query to see if the profile data is present but perhaps nested differently than expected. 5. If possible, try using Prisma Studio (you can run it with wasp db studio) to verify that the data relationships are correct in your database. If none of these steps resolve the issue, you might be encountering a bug in Wasp or Prisma. In this case, I would recommend reaching out to the Wasp community for support: 1. You can ask for help in the Wasp Discord channel. 2. Alternatively, you could file an issue on the Wasp GitHub repository, providing details about your schema, queries, and the unexpected behavior you're seeing. The Wasp team and community are usually very responsive and can provide more specific guidance based on your exact setup and code. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ---------------------- Sorry @CamBlackwood, I seem to be having a bit of trouble. Don't worry though, I've pinged my support and they will try to fix me up! :technologist: Perhaps try again in 15mins?
CamBlackwood
CamBlackwoodOP•3w ago
@kapa.ai I restarted wasp and it worked 😂 Thank you for your help as always my robot friend
kapa.ai
kapa.ai•3w ago
Let me check the knowledge base for you again. One moment! :books: ---------------------- I'm glad to hear that restarting Wasp resolved the issue! This is indeed a common solution for various development-related problems. Your experience aligns with what's mentioned in the Discord support thread about Prisma errors, where another user had a similar issue that was resolved by running wasp clean and then wasp start again. As a general tip, if you encounter unexpected behavior in Wasp, it's often helpful to try the following steps: 1. Restart the Wasp server (wasp start) 2. Run wasp clean followed by wasp start 3. Ensure all your dependencies are up to date These steps can often resolve issues related to caching, outdated builds, or temporary glitches in the development environment. Thank you for sharing your solution. It might help other users who encounter similar issues in the future. Happy coding with Wasp! ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ---------------------- Sorry @CamBlackwood, I seem to be having a bit of trouble. Don't worry though, I've pinged my support and they will try to fix me up! :technologist: Perhaps try again in 15mins?
Filip
Filip•3w ago
Hey @CamBlackwood, glad the bot could help you out! What was the problem here? I read the original question and it seems pretty weird

Did you find this page helpful?