Skip to content

Commit

Permalink
✅ fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
CMHopeSunshine committed May 16, 2024
1 parent 4b8a2bb commit c793ea9
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions tests/models.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Optional
from __future__ import annotations

import cherry
from tests.database import database
Expand All @@ -7,7 +7,7 @@


class User(cherry.Model):
id: Optional[int] = cherry.Field(default=None, primary_key=True, autoincrement=True)
id: int | None = cherry.Field(default=None, primary_key=True, autoincrement=True)
name: str = cherry.Field(unique=True, max_length=30)
introduce: str = cherry.Field(long_text=True)
age: int = 18
Expand All @@ -19,30 +19,33 @@ class User(cherry.Model):
class Student(cherry.Model):
id: cherry.AutoIntPK = None
name: str
school: cherry.ForeignKey[Optional["School"]] = None
school: School | None = cherry.Relationship(default=None, foreign_key=True)

cherry_config = {"database": database}


class School(cherry.Model):
id: cherry.AutoIntPK = None
name: str
students: cherry.ReverseRelation[list[Student]] = []
students: list[Student] = cherry.Relationship(
default_factory=list,
reverse_related=True,
)

cherry_config = {"database": database}


class Tag(cherry.Model):
name: cherry.PrimaryKey[str]
posts: cherry.ManyToMany[list["Post"]] = []
posts: list[Post] = cherry.Relationship(default_factory=list, many_to_many=True)

cherry_config = {"database": database}


class Post(cherry.Model):
id: cherry.AutoIntPK = None
title: str
tags: cherry.ManyToMany[list[Tag]] = []
tags: list[Tag] = cherry.Relationship(default_factory=list, many_to_many=True)

cherry_config = {"database": database}

Expand Down

0 comments on commit c793ea9

Please sign in to comment.