title: Tortoise ORM for Python no returns relations of entities (Pyndantic, FastAPI)
body: <p>I was making a sample Fast Api server with Tortoise ORM as an asynchronous orm library, but I just cannot seem to return the relations I have defined. These are my relations:</p>
  <pre><code># Category
  from tortoise.fields.data import DatetimeField
  from tortoise.models import Model
  from tortoise.fields import UUIDField, CharField
  from tortoise.fields.relational import ManyToManyField
  from tortoise.contrib.pydantic import pydantic_model_creator
  
  
  class Category(Model):
      id = UUIDField(pk=True)
      name = CharField(max_length=255)
      description = CharField(max_length=255)
      keywords = ManyToManyField(
          &quot;models.Keyword&quot;, related_name=&quot;categories&quot;, through=&quot;category_keywords&quot;
      )
      created_on = DatetimeField(auto_now_add=True)
      updated_on = DatetimeField(auto_now=True)
  
  
  
  Category_dto = pydantic_model_creator(Category, name=&quot;Category&quot;, allow_cycles = True)
  </code></pre>
  <pre><code># Keyword
  from models.expense import Expense
  from models.category import Category
  from tortoise.fields.data import DatetimeField
  from tortoise.fields.relational import ManyToManyRelation
  from tortoise.models import Model
  from tortoise.fields import UUIDField, CharField
  from tortoise.contrib.pydantic import pydantic_model_creator
  
  
  class Keyword(Model):
      id = UUIDField(pk=True)
      name = CharField(max_length=255)
      description = CharField(max_length=255)
      categories: ManyToManyRelation[Category]
      expenses: ManyToManyRelation[Expense]
      created_on = DatetimeField(auto_now_add=True)
      updated_on = DatetimeField(auto_now=True)
  
      class Meta:
          table=&quot;keyword&quot;
  
  
  Keyword_dto = pydantic_model_creator(Keyword)
  </code></pre>
  <p>The tables have been created correctly. When adding keywords to categories the db state is all good. The problem is when i want to query the categories and include the keywords. I have this code for that:</p>
  <pre><code>class CategoryRepository():
  
      @staticmethod
      async def get_one(id: str) -&gt; Category:
          category_orm = await Category.get_or_none(id=id).prefetch_related('keywords')
          if (category_orm is None):
              raise NotFoundHTTP('Category')
          return category_orm
  </code></pre>
  <p>Debugging the category_orm here I have the following:</p>
  <p><a href="https://i.stack.imgur.com/SBLnI.png" rel="noreferrer">category_orm debug at run-time</a></p>
  <p>Which kind of tells me that they are loaded.
  Then when i cant a Pydantic model I have this code</p>
  <pre><code>class CategoryUseCases():
  
      @staticmethod
      async def get_one(id: str) -&gt; Category_dto:
          category_orm = await CategoryRepository.get_one(id)
          category = await Category_dto.from_tortoise_orm(category_orm)
          return category
  </code></pre>
  <p>and debugging this, there is no <code>keywords</code> field</p>
  <p><a href="https://i.stack.imgur.com/Qecbp.png" rel="noreferrer">category (pydantic) debug at run-time</a></p>
  <p>Looking at the source code of tortoise orm for the function <code>from_tortoise_orm</code></p>
  <pre><code>@classmethod
      async def from_tortoise_orm(cls, obj: &quot;Model&quot;) -&gt; &quot;PydanticModel&quot;:
          &quot;&quot;&quot;
          Returns a serializable pydantic model instance built from the provided model instance.
  
          .. note::
  
              This will prefetch all the relations automatically. It is probably what you want.
  </code></pre>
  <p>But my relation is just not returned. Anyone have a similar experience ?</p>