How can I add a property to a SQL Model that is not a SQLAlchemy field? #1145
Unanswered
SergioPereo
asked this question in
Questions
Replies: 1 comment 1 reply
-
Have you ever tried this? |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
First Check
Commit to Help
Example Code
Description
Problem Description
I have a Role object that includes a permissions property. The structure of these permissions changes frequently, and I want to avoid using a static structure like an Enum or Value Object pattern. Instead, I plan to store the permissions as JSON in a MongoDB collection, which will be dynamically retrieved and saved based on the role's ID.
I’m using SQLModel because I like how it integrates schemas and models, avoiding the need for separate definitions. However, I'm facing a challenge with storing and retrieving the permissions attribute. Since the permissions are stored in MongoDB, I get the following error when trying to include the Permissions schema as a property of the SQLModel:
ValueError: <class 'app.template.schemas.Permissions'> has no matching SQLAlchemy type
Question
Is there a recommended way to integrate MongoDB storage with SQLModel for this kind of use case? Or should I separate the Role between saves into distinct models, managing them independently?
Operating System
Linux
Operating System Details
I'm using WSL2
Distributor ID: Ubuntu
Description: Ubuntu 22.04.4 LTS
Release: 22.04
Codename: jammy
SQLModel Version
0.0.22
Python Version
3.12
Additional Context
No response
Beta Was this translation helpful? Give feedback.
All reactions