You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When I want to avoid using the column names found in the SQL table, as in the ExampleModel below, I create custom column names to correspond to them. However, when I try to perform an upsert operation on the table's service, instead of getting the custom column names I provided to the model in the to_dict function, it retrieves the column names from the SQL table. Hence, it does not match the column names in the model.
We've encountered this issue before with the model_from_dict function, and we fixed it by adding the following code. #78
defto_dict(self, exclude: set[str] |None=None) ->dict[str, Any]:
"""Convert model to dictionary. Returns: dict[str, Any]: A dict representation of the model """exclude= {"sa_orm_sentinel", "_sentinel"}.union(self._sa_instance_state.unloaded).union(excludeor []) # type: ignore[attr-defined]return {field.name: getattr(self, field.name) forfieldinself.__table__.columnsiffield.namenotinexclude}
Must be:
defto_dict(self, exclude: set[str] |None=None) ->dict[str, Any]:
"""Convert model to dictionary. Returns: dict[str, Any]: A dict representation of the model """exclude= {"sa_orm_sentinel", "_sentinel"}.union(self._sa_instance_state.unloaded).union(excludeor []) # type: ignore[attr-defined]return {field: getattr(self, field) forfieldinself.__mapper__.columns.keys() iffieldnotinexclude}
1. Create a model and define column names different from those in the SQL table.
2. Create a service for the model.
3. Use an upsert method within the service.
4. Finally, trigger the place where you used upsert in this service.
Screenshots
"In the format of: ![SCREENSHOT_DESCRIPTION](SCREENSHOT_LINK.png)"
Logs
No response
Jolt Project Version
v0.9.0
Platform
Linux
Mac
Windows
Other (Please specify in the description above)
Funding
If you would like to see an issue prioritized, make a pledge towards it!
We receive the pledge once the issue is completed & verified
The text was updated successfully, but these errors were encountered:
Description
When I want to avoid using the column names found in the SQL table, as in the ExampleModel below, I create custom column names to correspond to them. However, when I try to perform an upsert operation on the table's service, instead of getting the custom column names I provided to the model in the to_dict function, it retrieves the column names from the SQL table. Hence, it does not match the column names in the model.
We've encountered this issue before with the model_from_dict function, and we fixed it by adding the following code. #78
If we need to continue from the current issue, we can proceed with the following model.
Model:
Current:
Must be:
URL to code causing the issue
https://github.com/jolt-org/advanced-alchemy/blob/main/advanced_alchemy/base.py#L215
MCVE
# Your MCVE code here
Steps to reproduce
Screenshots
"In the format of:
![SCREENSHOT_DESCRIPTION](SCREENSHOT_LINK.png)
"Logs
No response
Jolt Project Version
v0.9.0
Platform
Funding
The text was updated successfully, but these errors were encountered: