Relationships
Ryx supports the three classic database relationships.
What You'll Learn
- ForeignKey — Many-to-one relationships
- OneToOne — One-to-one relationships
- ManyToMany — Many-to-many with join tables
- select_related — Eager loading with JOINs
- prefetch_related — Eager loading with IN queries
Quick Overview
class Author(Model):
name = CharField(max_length=100)
class Post(Model):
title = CharField(max_length=200)
author = ForeignKey(Author, on_delete="CASCADE") # Many-to-one
class Profile(Model):
user = OneToOneField(User) # One-to-one
class Tag(Model):
name = CharField(max_length=50)
posts = ManyToManyField(Post) # Many-to-many