Replies: 2 comments
-
It would be wrong to say that those are equal, by default, as If you want, you can however define the equality check how you want, by overriding It might be confusing to make non-equal objects equal, though, so perhaps for your purpose you want some new method, like |
Beta Was this translation helpful? Give feedback.
-
I ended up here because I've expected comparing SQLModel objects to work like comparing Pydantic objects and well, they don't. I do a query, as a result I end up with a list of SQLModel objects. I compare them against external database - if the corresponding object has been modified in the external database, I have the object in my database. So I create a new object using data from external database, and compare it to the object returned from querying my database. I expected it to act like pydantic models, but it seems each SQLModel object is different because of internal properties. |
Beta Was this translation helpful? Give feedback.
-
First Check
Commit to Help
Example Code
Description
In our project, we read data from files or APIs and use it to create objects. Then, we check whether we already have that data in our database by comparing some key data points. If we find a match, we want to check if the new object is equal to the one in the database.
Currently, we use a SQLAlchemy class and a Pydantic model that have similar fields for this task. However, we recently discovered SQLModel and hoped to simplify the process by using it for both the data and database models, with inheritance.
However, when we tried this approach, we noticed that the objects are never considered equal. We're not sure if we made a mistake or if there's something we need to change to achieve the desired behavior.
Operating System
Linux, macOS
Operating System Details
No response
SQLModel Version
0.0.6
Python Version
3.9
Additional Context
No response
Beta Was this translation helpful? Give feedback.
All reactions