Using Query Syntax to filter by FK's field

hey there, I have a schema of users and their pets name and type. a user can only own one pet, and a pet could have several owners. how would I use query syntax to get all the users that own a dog (type === 'dog')?
export const users = pgTable('users', {
    id: serial('id').primaryKey(),
    petId: text('petId'),
        name: text('name'),
});
export const pets = pgTable('pets', {
    id: serial('id').primaryKey(),
    name: text('name'),
        type: text('type'),
});

export const usersRelations = relations(users, ({ one }) => ({
    pet: one(pets, { fields: [user.petId], references: [pet.id] }),
        
}));
Was this page helpful?