GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | |||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | |||||||||||||||||
GeezerVison is showing github.com — Support hybrid_property, column_property, declared_attr by 50Bytes-dev · Pull Request #801 · fastapi/sqlmodel Conversationclass Item(SQLModel, table=True): id: Optional[int] = Field(default=None, primary_key=True) value: float hero_id: int = Field(foreign_key="hero.id") hero: "Hero" = Relationship(back_populates="items") class Hero(SQLModel, table=True): id: Optional[int] = Field(default=None, primary_key=True) name: str items: list[Item] = Relationship(back_populates="hero") @hybrid_property def total_items(self): return sum([item.value for item in self.items], 0) @total_items.inplace.expression @classmethod def _total_items_expression(cls): return ( select(func.coalesce(func.sum(Item.value), 0)) .where(Item.hero_id == cls.id) .correlate(cls) .label("total_items") ) @hybrid_property def status(self): return "active" if self.total_items > 0 else "inactive" @status.inplace.expression @classmethod def _status_expression(cls): return ( select(case((cls.total_items > 0, "active"), else_="inactive")) .label("status") )
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
This was referenced
Author
All reactions
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page.
8 tasks done
awoimbee
approved these changes
|
|
Please merge it asap :3. I need it, lol. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
hey can we get this merged in |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
@tiangolo Could you please take a look at this MR. The functionality is very nice. Would be a nice addition. Doesn't seem to clash with overall design |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Following this example I am getting Even if I do But I think we can get the same result with |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Any movement to get this functionality in? |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
…enhance association proxy handling
…perties and enhance setter handling
…s for fallback behavior
…fallback values in deferred properties; add comprehensive tests for async scenarios and edge cases
…d tests to verify fallback behavior after refresh and loading
…y; add basic tests for fallback behavior and undefer functionality
… typing tests for compatibility
|
any updates on this? |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
This pull request has a merge conflict that needs to be resolved. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
I think I can go a bit further than what this pr had in mind. I was thinking about combining computed_feilds and hybrid_property column_property and declared_attr together. Does anyone have any tips and suggestions? I'll try and use what this pr had in mind as a blueprint. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
…configuration and utility functions for SQLModel
|
@50Bytes-dev Glad to see your pr is still alive, mind if I help you review it? |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
…columns by schema; update col function to return InstrumentedAttribute for better type safety
… relations in SQLModel
…Path and AliasChoices for enhanced flexibility
|
@50Bytes-dev Have you tried adding some tests to the pytest to ensure that this implementation works? |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Yes, I have basic tests. I use this PR in the production of my projects and make sure that everything works correctly. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
@50Bytes-dev thanks, for that piece of code. Is there any chance for release some time soon. I have a use case starting from next week and I'd like to omit a vanilla sqlalchemy workaround :) |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Release where? Personally, I just use the repository and don't plan to release anything anywhere. I recommend trying it this way too, it's quite convenient. dependencies = [ "sqlmodel", ] [tool.uv.sources] sqlmodel = { git = "https://github.com/50Bytes-dev/sqlmodel.git", rev = "833b8700e5006177d1a57fd8b3109bd625a358de" } |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
@50Bytes-dev Okay, sorry. I thought that the PR is meant to be merged at some point. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
I think that the main repository is dead and unlikely to be developed further, so I created my own fork where I implement all the necessary functions myself. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
…eAttribute for better type safety
The main repo of what? FastAPI, SQLmodel? If there is no PR, in SQLModel I assume, nobody can check it, thus it appears obv. dead. Though if you look at the commit history in main, all is fine Looking for a method to introduce calculated column easily. Got to this to just read that lol |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.