0.11.1 Summary
Added
one_or_noneparameter to FastCRUDgetmethod (defaultFalse)nest_joinsparameter to FastCRUDget_joinedandget_multi_joined(defaultFalse)
Detailed
get
By default, the get method in FastCRUD returns the first object matching all the filters it finds.
If you want to ensure the one_or_none behavior, you may pass the parameter as True:
crud.get(
async_session,
one_or_none=True,
category_id=1
)get_joined and get_multi_joined
By default, FastCRUD joins all the data and returns it in a single dictionary.
Let's define two tables:
class User(Base):
__tablename__ = "user"
id = Column(Integer, primary_key=True)
name = Column(String)
tier_id = Column(Integer, ForeignKey("tier.id"))
class Tier(Base):
__tablename__ = "tier"
id = Column(Integer, primary_key=True)
name = Column(String, unique=True)And join them with FastCRUD:
user_tier = await user_crud.get_joined(
db=db,
model=Tier,
join_on=User.tier_id == Tier.id,
join_type="left",
join_prefix="tier_",,
id=1
)We'll get:
{
"id": 1,
"name": "Example",
"tier_id": 1,
"tier_name": "Free",
}Now, if you want the joined data in a nested dictionary instead, you may just pass nest_joins=True:
user_tier = await user_crud.get_joined(
db=db,
model=Tier,
join_on=User.tier_id == Tier.id,
join_type="left",
join_prefix="tier_",
nest_joins=True,
id=1,
)And you will get:
{
"id": 1,
"name": "Example",
"tier": {
"id": 1,
"name": "Free",
},
}This works for both get_joined and get_multi_joined.
Warning
Note that the final "_" in the passed "tier_" is stripped.
What's Changed
- Skip count call when possible by @JakNowy in #51
- refactor: ♻️ reuse of select method in FastCRUD by @dubusster in #55
- feat: ✨ add strict parameter to FastCRUD
getmethod by @dubusster in #54 - Nested responses by @igorbenav in #56
New Contributors
Full Changelog: v0.11.0...v0.11.1