我正在尝试使用 Prisma 和其他工具为我的应用程序创建一个友谊机制。在文档中,它显示了以下示例,说明如何创建多对多自关系:
model User {
id Int @id @default(autoincrement())
name String?
followedBy Follows[] @relation("following")
following Follows[] @relation("follower")
}
model Follows {
follower User @relation("follower", fields: [followerId], references: [id])
followerId Int
following User @relation("following", fields: [followingId], references: [id])
followingId Int
@@id([followerId, followingId])
}
Run Code Online (Sandbox Code Playgroud)
我已经实现了这个并且它有效,但是问题是对于友谊来说,没有“关注”和“跟随者”,你们只是朋友。目前,当我查询时,我必须查询这两个字段才能找到用户的所有朋友。有没有办法只用一个字段来定义这种类型的关系?那么我们只有一个用户的好友列表吗?
语境
我知道这个问题在 stackoverflow 上已经被问过多次,相信我,我已经仔细研究过它们并尝试了尽可能多的方法。
问题
我有一个使用 Firebase 身份验证的 React Native - Expo 应用程序。用户在每次应用程序刷新时都会注销(令人愤怒)。因此,我按照许多其他答案的建议添加了一个侦听器。这是添加在我的登录页面上的。每次刷新后,我的控制台中都会记录“无用户”。
useEffect(() => {
const unsubscribe = firebase.auth().onAuthStateChanged(user => {
if (user) {
navigation.replace('Main');
console.log('User logged in!');
}
else {
console.log("No user");
}
});
return unsubscribe;
}, []);
Run Code Online (Sandbox Code Playgroud)
由于我使用的是 V9.6.10,因此我还尝试了此处提供的模块化方法作为类似问题的答案。
其他问题中提供的这些答案似乎对人们有用,但到目前为止还没有对我有用。如果需要更多信息来解决问题,我很乐意提供。
这是我花了 9 个月时间开发的应用程序的最后一个问题之一,并且在一段时间内一直是我的克星,非常感谢您的帮助!