Oreki
Oreki
Explore posts from servers
DTDrizzle Team
Created by Oreki on 1/26/2024 in #help
advanced relational query builder
Hmm I thought so as well, thanks
13 replies
DTDrizzle Team
Created by Oreki on 1/26/2024 in #help
advanced relational query builder
a card can only have one character, but a character can have many different cards
13 replies
DTDrizzle Team
Created by Oreki on 1/26/2024 in #help
advanced relational query builder
i don't get a where key for some reason
13 replies
DTDrizzle Team
Created by Oreki on 1/26/2024 in #help
advanced relational query builder
No description
13 replies
DTDrizzle Team
Created by Oreki on 1/26/2024 in #help
advanced relational query builder
context.database.query.cards.findMany({
where: () => eq(cards.ownerId, user.raw.id),
orderBy: () =>
sort ? sortOptions[sort as keyof typeof sortOptions] : [],
limit: 10,
offset,
with: {
character: {

},
},
}),
context.database.query.cards.findMany({
where: () => eq(cards.ownerId, user.raw.id),
orderBy: () =>
sort ? sortOptions[sort as keyof typeof sortOptions] : [],
limit: 10,
offset,
with: {
character: {

},
},
}),
13 replies
DTDrizzle Team
Created by Oreki on 1/26/2024 in #help
advanced relational query builder
yes gimme a sec
13 replies
DTDrizzle Team
Created by Oreki on 1/26/2024 in #help
advanced relational query builder
i tried that as well, only if i had a where key in my relational query builder
13 replies
DTDrizzle Team
Created by Oreki on 1/26/2024 in #help
advanced relational query builder
yeah but that is not what i want to do, in that particular example i want all the cards who have a relation to characters table and the respective character's element is lets say for example fire
13 replies
DTDrizzle Team
Created by Skyler on 6/4/2023 in #help
Many to many relationship between one type
A post can be bookmarked by many, a user can bookmark many posts etc
20 replies
DTDrizzle Team
Created by Skyler on 6/4/2023 in #help
Many to many relationship between one type
I'm creating a blog application so I need to create relations for bookmarks etc
20 replies
DTDrizzle Team
Created by Skyler on 6/4/2023 in #help
Many to many relationship between one type
I did not, but I learned that having a many-to-many relation would be an advanced concept for me
20 replies
DTDrizzle Team
Created by Skyler on 6/4/2023 in #help
Many to many relationship between one type
this seems to be working, thank you!
20 replies
DTDrizzle Team
Created by Skyler on 6/4/2023 in #help
Many to many relationship between one type
Oh this is advanced, I'll try recreating this as per my following/followers tomorrow, thanks!
20 replies
DTDrizzle Team
Created by Skyler on 6/4/2023 in #help
Many to many relationship between one type
Thank you!
20 replies
DTDrizzle Team
Created by Skyler on 6/4/2023 in #help
Many to many relationship between one type
Will you be able to show me just the followers/following part of your schema? If not that's fine, what I thought of doing is, I'd just run raw SQL command to generate followers/following many to many relational tables and introspect it with drizzle kit
20 replies
DTDrizzle Team
Created by Skyler on 6/4/2023 in #help
Many to many relationship between one type
Lmao they're commented because if I uncomment them it breaks
20 replies
DTDrizzle Team
Created by Oreki on 8/7/2023 in #help
relations help
i've tried doing this but this also does not work
export const userRelations = relations(users, ({ one, many }) => ({
invitee: one(users, {
fields: [users.invitedBy],
references: [users.id],
relationName: 'invitee',
}),
followers: many(followers),
following: many(following),
posts: many(post),
comments: many(comment),
likes: many(like),
}));

export const followers = pgTable(
'user_followers',
{
userId: text('user_id')
.notNull()
.references(() => users.id),
followerId: text('follower_id')
.notNull()
.references(() => users.id),
},
(t) => ({
cpk: primaryKey(t.userId, t.followerId),
}),
);

export const following = pgTable(
'user_following',
{
userId: text('user_id')
.notNull()
.references(() => users.id),
followingId: text('following_id')
.notNull()
.references(() => users.id),
},
(t) => ({
cpk: primaryKey(t.userId, t.followingId),
}),
);

export const followersRelations = relations(followers, ({ one }) => ({
user: one(users, {
fields: [followers.userId],
references: [users.id],
relationName: 'followers',
}),
follower: one(users, {
fields: [followers.followerId],
references: [users.id],
relationName: 'follower',
}),
}));

export const followingRelations = relations(following, ({ one }) => ({
user: one(users, {
fields: [following.userId],
references: [users.id],
relationName: 'followers',
}),
following: one(users, {
fields: [following.followingId],
references: [users.id],
relationName: 'following',
}),
}));
export const userRelations = relations(users, ({ one, many }) => ({
invitee: one(users, {
fields: [users.invitedBy],
references: [users.id],
relationName: 'invitee',
}),
followers: many(followers),
following: many(following),
posts: many(post),
comments: many(comment),
likes: many(like),
}));

export const followers = pgTable(
'user_followers',
{
userId: text('user_id')
.notNull()
.references(() => users.id),
followerId: text('follower_id')
.notNull()
.references(() => users.id),
},
(t) => ({
cpk: primaryKey(t.userId, t.followerId),
}),
);

export const following = pgTable(
'user_following',
{
userId: text('user_id')
.notNull()
.references(() => users.id),
followingId: text('following_id')
.notNull()
.references(() => users.id),
},
(t) => ({
cpk: primaryKey(t.userId, t.followingId),
}),
);

export const followersRelations = relations(followers, ({ one }) => ({
user: one(users, {
fields: [followers.userId],
references: [users.id],
relationName: 'followers',
}),
follower: one(users, {
fields: [followers.followerId],
references: [users.id],
relationName: 'follower',
}),
}));

export const followingRelations = relations(following, ({ one }) => ({
user: one(users, {
fields: [following.userId],
references: [users.id],
relationName: 'followers',
}),
following: one(users, {
fields: [following.followingId],
references: [users.id],
relationName: 'following',
}),
}));
2 replies
DTDrizzle Team
Created by Skyler on 6/4/2023 in #help
Many to many relationship between one type
were you guys able to get this to work? i get an error relation "following" or "followers" does not exist
export const userRelations = relations(users, ({ one, many }) => ({
invitee: one(users, {
fields: [users.invitedBy],
references: [users.id],
}),
// followers: many(following, {
// relationName: 'followers',
// }),
// following: many(following, {
// relationName: 'following',
// }),
posts: many(post),
comments: many(comment),
likes: many(like),
}));

export const following = pgTable(
'following',
{
userId: text('user_id')
.references(() => users.id)
.notNull(),
followingId: text('following_id')
.references(() => users.id)
.notNull(),
},
(table) => ({
cpk: primaryKey(table.userId, table.followingId),
}),
);

export const FollowingRelations = relations(following, ({ one }) => ({
user: one(users, {
fields: [following.userId],
references: [users.id],
relationName: 'followers',
}),
following: one(users, {
fields: [following.followingId],
references: [users.id],
relationName: 'following',
}),
}));
export const userRelations = relations(users, ({ one, many }) => ({
invitee: one(users, {
fields: [users.invitedBy],
references: [users.id],
}),
// followers: many(following, {
// relationName: 'followers',
// }),
// following: many(following, {
// relationName: 'following',
// }),
posts: many(post),
comments: many(comment),
likes: many(like),
}));

export const following = pgTable(
'following',
{
userId: text('user_id')
.references(() => users.id)
.notNull(),
followingId: text('following_id')
.references(() => users.id)
.notNull(),
},
(table) => ({
cpk: primaryKey(table.userId, table.followingId),
}),
);

export const FollowingRelations = relations(following, ({ one }) => ({
user: one(users, {
fields: [following.userId],
references: [users.id],
relationName: 'followers',
}),
following: one(users, {
fields: [following.followingId],
references: [users.id],
relationName: 'following',
}),
}));
20 replies