Convert the object to a dictionary. Args: kwargs: Ignored but needed for compatibility. Returns: The object as a dictionary.
(self, **kwargs)
| 89 | return value |
| 90 | |
| 91 | def dict(self, **kwargs): |
| 92 | """Convert the object to a dictionary. |
| 93 | |
| 94 | Args: |
| 95 | kwargs: Ignored but needed for compatibility. |
| 96 | |
| 97 | Returns: |
| 98 | The object as a dictionary. |
| 99 | """ |
| 100 | base_fields = {name: getattr(self, name) for name in self.__fields__} |
| 101 | relationships = {} |
| 102 | # SQLModel relationships do not appear in __fields__, but should be included if present. |
| 103 | for name in self.__sqlmodel_relationships__: |
| 104 | try: |
| 105 | relationships[name] = self._dict_recursive(getattr(self, name)) |
| 106 | except sqlalchemy.orm.exc.DetachedInstanceError: |
| 107 | # This happens when the relationship was never loaded and the session is closed. |
| 108 | continue |
| 109 | return { |
| 110 | **base_fields, |
| 111 | **relationships, |
| 112 | } |
| 113 | |
| 114 | @staticmethod |
| 115 | def create_all(): |