Inheritance with_children is invalid #411
-
I use beanie version 1.15.1. Refer to official documentation https://beanie-odm.dev/tutorial/inheritance/ from typing import Optional, List
from motor.motor_asyncio import AsyncIOMotorClient
from pydantic import BaseModel
from beanie import Document, Link, init_beanie
class Vehicle(Document):
"""Inheritance scheme bellow"""
# Vehicle
# / | \
# / | \
# Bicycle Bike Car
# \
# \
# Bus
# shared attribute for all children
color: str
class Settings:
is_root = True
class Fuelled(BaseModel):
"""Just a mixin"""
fuel: Optional[str]
class Car(Vehicle, Fuelled):
body: str
class Bus(Car, Fuelled):
"""Inheritance chain is Vehicle -> Car -> Bus, it is also stored in Vehicle collection"""
seats: int
await Car(color='white', body='crossover', fuel='diesel').insert()
await Bus(color='white', seats=80, body='bus', fuel='diesel').insert()
white_vehicles = await Vehicle.find(Vehicle.color == 'white', with_children=True).to_list()
print(white_vehicles)
"""
[
Vehicle(id=ObjectId('636b72d8aea4065b3b6cd2ba'), revision_id=None, color='white'),
Vehicle(id=ObjectId('636b72d8aea4065b3b6cd2bb'), revision_id=None, color='white'),
]
"""
white_vehicles = await Vehicle.find(Vehicle.color == 'white').to_list()
print(white_vehicles)
"""
[
Vehicle(id=ObjectId('636b72d8aea4065b3b6cd2ba'), revision_id=None, color='white'),
Vehicle(id=ObjectId('636b72d8aea4065b3b6cd2bb'), revision_id=None, color='white'),
]
""" Not quite the same as the official documentation.
Where am I doing wrong? |
Beta Was this translation helpful? Give feedback.
Answered by
roman-right
Nov 9, 2022
Replies: 1 comment 2 replies
-
Hey. Yes, you are right. Thank you for the catch. It will be fixed in ~ 1 hour. I'll inform you here |
Beta Was this translation helpful? Give feedback.
2 replies
Answer selected by
hgalytoby
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hey. Yes, you are right. Thank you for the catch. It will be fixed in ~ 1 hour. I'll inform you here