mongomock_motor icon indicating copy to clipboard operation
mongomock_motor copied to clipboard

It doesn't find by relation entity id

Open resulyrt93 opened this issue 10 months ago • 3 comments

I'm using your excellent tool with beanie but i can't find a record by relation id. You can produce problem with following code block.

Reproduce Code

import asyncio

from beanie import init_beanie, Document, Link
from mongomock_motor import AsyncMongoMockClient


class School(Document):
    name: str

    class Settings:
        name = "school"


class Student(Document):
    name: str
    surname: str
    school: Link[School]

    class Settings:
        name = "student"


async def start_env():
    client = AsyncMongoMockClient()
    await init_beanie(database=client["test-db"], document_models=[School, Student])

    school = School(name="Harvard")
    await school.insert()

    student = Student(name="Barack", surname="Obama", school=school.id)
    await student.insert()

    harvard_students = await Student.find(Student.school.id == school.id).to_list()
    print("Harvard students: ", harvard_students)


if __name__ == "__main__":
    asyncio.run(start_env())

Output

> Harvard students: []

requirements.txt

beanie==1.17.0
mongomock_motor==0.0.21

when I fetch all students or all schools i can see my insertions and relations between them.

Thank you.

resulyrt93 avatar Aug 28 '23 11:08 resulyrt93