Skip to content

Commit 61e7055

Browse files
committed
docs updated
1 parent 368851d commit 61e7055

File tree

3 files changed

+84
-0
lines changed

3 files changed

+84
-0
lines changed

docs/advanced/joins.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,49 @@ This works for both `get_joined` and `get_multi_joined`.
201201

202202
Note that the final `"_"` in the passed `"tier_"` is stripped.
203203

204+
#### Returning Pydantic Models with `return_as_model`
205+
206+
By default, `get_joined` returns dictionaries containing the joined data. However, you can use the `return_as_model` parameter to get Pydantic model instances instead:
207+
208+
```python
209+
# Using a schema that includes joined fields
210+
class UserWithTier(BaseModel):
211+
id: int
212+
name: str
213+
tier_id: int
214+
tier_name: str
215+
216+
# Returns a dictionary (default behavior)
217+
user_dict = await user_crud.get_joined(
218+
db=db,
219+
join_model=Tier,
220+
join_prefix="tier_",
221+
schema_to_select=UserWithTier,
222+
return_as_model=False, # Default
223+
id=1,
224+
)
225+
# Result: {"id": 1, "name": "Example", "tier_id": 1, "tier_name": "Free"}
226+
227+
# Returns a Pydantic model instance
228+
user_model = await user_crud.get_joined(
229+
db=db,
230+
join_model=Tier,
231+
join_prefix="tier_",
232+
schema_to_select=UserWithTier,
233+
return_as_model=True,
234+
id=1,
235+
)
236+
# Result: UserWithTier(id=1, name="Example", tier_id=1, tier_name="Free")
237+
```
238+
239+
!!! TIP "Schema Design for Joined Data"
240+
241+
When using `return_as_model=True`, ensure your schema includes all the fields that will be present in the flattened result, including joined fields with their prefixes.
242+
243+
!!! NOTE "Required Parameters"
244+
245+
When `return_as_model=True`, the `schema_to_select` parameter is required. FastCRUD will raise a `ValueError` if you try to use `return_as_model=True` without providing a schema.
246+
204247
!!! WARNING "join_prefix and return_as_model Compatibility"
205248

206249
When using `return_as_model=True` with `nest_joins=True`, ensure that your `join_prefix` (minus trailing "_") matches the field name in your Pydantic schema. Otherwise, FastCRUD will raise a `ValueError` with clear guidance on how to fix the mismatch.

docs/changelog.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,38 @@
55
The Changelog documents all notable changes made to FastCRUD. This includes new features, bug fixes, and improvements. It's organized by version and date, providing a clear history of the library's development.
66
___
77

8+
## [0.19.2] - Nov 15, 2025
9+
10+
#### Added
11+
- **get_joined Method Overloads** by [@igorbenav](https://github.com/igorbenav)
12+
- Added missing `@overload` signatures for `get_joined()` method to support proper type inference
13+
- Added `return_as_model` parameter for converting joined results to Pydantic models
14+
- Enhanced type safety: returns `SelectSchemaType` when `return_as_model=True`, `dict` when `False`
15+
- Consistent API with other CRUD methods like `get()`, `update()`, etc.
16+
17+
#### Improved
18+
- **create Method Performance and Consistency** by [@igorbenav](https://github.com/igorbenav)
19+
- Removed unnecessary database round-trip by eliminating redundant `get()` call after creation
20+
- Added deprecation warnings for upcoming API consistency changes in next major version
21+
- Fixed type hints to match actual implementation behavior (removed incorrect `None` return type)
22+
23+
#### Deprecated
24+
- **create Method Behavior Changes** (Warnings Added)
25+
- `create()` without `schema_to_select` will return `None` instead of SQLAlchemy model in next major version
26+
- `create()` with `schema_to_select` will properly respect `return_as_model` parameter in next major version
27+
- These changes align `create()` behavior with `update()` and other CRUD methods for consistency
28+
29+
#### Fixed
30+
- **Type Safety Issues** by [@igorbenav](https://github.com/igorbenav)
31+
- Fixed `get_joined()` method type annotations to properly reflect actual return types
32+
- Corrected `create()` method type hints to remove impossible `None` return type
33+
- Enhanced test coverage with 8 new comprehensive tests for `get_joined` return type variations
34+
35+
#### Breaking Changes
36+
⚠️ **None** - This release maintains full backward compatibility with 0.19.1. Deprecation warnings provide clear migration path for next major version.
37+
38+
___
39+
840
## [0.19.1] - Nov 10, 2025
941

1042
#### Improved

docs/usage/crud.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,15 @@ create(
128128
new_item = await item_crud.create(db, CreateItemSchema(name="New Item"))
129129
```
130130

131+
!!! WARNING "Deprecated Behavior"
132+
133+
**Upcoming Changes in Next Major Version**: The `create()` method currently behaves inconsistently compared to other CRUD methods like `update()`. It will change:
134+
135+
- **Currently without `schema_to_select`**: Returns SQLAlchemy model → **Will return `None`**
136+
- **Currently with `schema_to_select`**: Bypasses `return_as_model` parameter → **Will respect `return_as_model` like other methods**
137+
138+
This makes `create()` consistent with `update()` behavior. Current usage patterns will trigger deprecation warnings. See [changelog](../changelog.md#0192---nov-15-2025) for details.
139+
131140
!!! WARNING
132141

133142
Note that naive `datetime` such as `datetime.utcnow` is not supported by `FastCRUD` as it was [deprecated](https://github.com/python/cpython/pull/103858).

0 commit comments

Comments
 (0)