0Pricing
Next.js 15 Fullstack Web Apps · Ders

Prisma ile İlişkiler ve Gelişmiş Sorgular

Bire çok ve çoka çok ilişkileri modelleyin; ardından iç içe yazma, include, select, filtreleme ve sayfalama kullanarak bu ilişkiler arasında sorgulama yapın.

Prisma ile İlişkiler ve Gelişmiş Sorgular, CoddyKit'te ücretsiz bir Next.js 15 Fullstack Web Apps dersidir. Bu, 4 dersinin 4. dersidir. Aşağıdan dersin tamamını ücretsiz okuyabilir, sonra tarayıcıda yerleşik kod editörü ve 7/24 yapay zeka koçu ile uygulamalı olarak pratik yapabilirsin. Bu, Next.js 15 Fullstack Web Apps öğrenme yolunun bir parçasıdır ve ilerlemeniz web ve CoddyKit uygulaması arasında senkronize olur. Next.js 15 Fullstack Web Apps kursu toplamda 4 dersten oluşur.

Bu dersin bazı bölümleri henüz çevrilmemiş olup İngilizce olarak gösterilmektedir.

Why Relations?

Real data is connected: a user has many posts, a post has many tags. Prisma models these relations in the schema so you can traverse them in type-safe queries.

One-to-Many in the Schema

A one-to-many relation links a parent to many children via a foreign key. Define both sides in the schema.

model User {
  id    Int    @id @default(autoincrement())
  posts Post[]
}
model Post {
  id       Int  @id @default(autoincrement())
  authorId Int
  author   User @relation(fields: [authorId], references: [id])
}

Many-to-Many

Prisma supports implicit many-to-many with just array fields on both sides; it manages the join table for you.

model Post { id Int @id @default(autoincrement()) tags Tag[] }
model Tag  { id Int @id @default(autoincrement()) posts Post[] }

Including Related Data

By default queries return only the model fields. Use include to fetch related records too.

const user = await prisma.user.findUnique({
  where: { id: 1 },
  include: { posts: true },
});

Selecting Specific Fields

Use select to fetch only the columns you need — leaner payloads and faster queries. You can nest select for relations.

const posts = await prisma.post.findMany({
  select: { id: true, title: true, author: { select: { name: true } } },
});

Nested Writes

Create a parent and its children in one call with a nested create. Prisma runs it in a transaction.

await prisma.user.create({
  data: {
    name: 'Ada',
    posts: { create: [{ title: 'Hello' }, { title: 'World' }] },
  },
});

Filtering with where

Build rich filters with operators like contains, gt, in, and combine them with AND/OR.

const recent = await prisma.post.findMany({
  where: {
    published: true,
    title: { contains: 'Prisma' },
  },
});

Filtering on Relations

You can filter a parent by a condition on its children using some, every, or none.

const authors = await prisma.user.findMany({
  where: { posts: { some: { published: true } } },
});

Sorting and Pagination

Order results with orderBy and page with take/skip (offset) for classic pagination.

const page = await prisma.post.findMany({
  orderBy: { createdAt: 'desc' },
  take: 10,
  skip: 20,
});

Cursor Pagination

For large or live datasets, cursor-based pagination is more stable than offset. Pass the last seen id as a cursor.

const next = await prisma.post.findMany({
  take: 10,
  cursor: { id: lastId },
  skip: 1,
});

Avoiding N+1 Queries

Fetching a list and then querying each item separately causes the N+1 problem. Prisma avoids it: use a single include to load relations in one optimized query rather than looping.

Quick Check

Test your Prisma relations knowledge.

Recap

You learned relational querying with Prisma:

  • Model one-to-many and many-to-many relations in the schema
  • Fetch relations with include; trim fields with select
  • Nested writes create parents and children atomically
  • Filter on relations, paginate with take/skip or cursors, and avoid the N+1 problem

Sıkça Sorulan Sorular

“Prisma ile İlişkiler ve Gelişmiş Sorgular” dersi ücretsiz mi?

Evet — “Prisma ile İlişkiler ve Gelişmiş Sorgular” dersin tüm metni burada web'de ücretsiz olarak okunabilir. Etkileşimli olarak pratik yapmak (yerleşik kod editörü ve 7/24 yapay zeka koçu) ve Next.js 15 Fullstack Web Apps kursunun geri kalanını açmak için CoddyKit PRO'ya yükselt. Next.js 15 Fullstack Web Apps kursu toplamda 4 dersten oluşur.

“Prisma ile İlişkiler ve Gelişmiş Sorgular” dersinde ne öğreneceğim?

Bire çok ve çoka çok ilişkileri modelleyin; ardından iç içe yazma, include, select, filtreleme ve sayfalama kullanarak bu ilişkiler arasında sorgulama yapın. Next.js 15 Fullstack Web Apps ile uygulamalı kodu tarayıcıda doğrudan çalıştırarak pratik yaparsın ve 7/24 yapay zeka koçu dersi çalışırken sorularını yanıtlar.

Next.js 15 Fullstack Web Apps öğrenmeye başlamak için deneyim gerekli mi?

Önceden deneyim gerekmez. CoddyKit'te Next.js 15 Fullstack Web Apps, başlangıçtan ileri seviyeye kadar yapılandırıldığı için buradan başlayabilir veya başından başlayıp kendi hızında ilerleme yapabilirsin. Bu, 4 dersinin 4. dersidir.

“Prisma ile İlişkiler ve Gelişmiş Sorgular” dersi ne kadar sürer?

Çoğu CoddyKit dersi yaklaşık 5–10 dakika sürer. Her biri kısa ve etkileşimli olduğu için sabit ilerleme yaparsın ve web ile uygulama arasında tam olarak bıraktığın yerden devam edebilirsin.

Bu Next.js 15 Fullstack Web Apps dersinde kod yazıp çalıştırabilir miyim?

Evet. Her Next.js 15 Fullstack Web Apps dersi yerleşik bir kod editörü içerir, bu sayede tarayıcıda gerçek kod yazıp çalıştırabilir ve anlık yapay zeka geri bildirimi alırsın — yerel kurulum gerekli değildir.

Bu kursun tüm dersleri

  1. Prisma ORM'ye Giriş
  2. Prisma Şeması Tasarımı ve Geçişler
  3. Prisma İstemcisiyle CRUD İşlemleri
  4. Prisma ile İlişkiler ve Gelişmiş Sorgular
← Next.js 15 Fullstack Web Apps Sayfasına Dön