File tree Expand file tree Collapse file tree 4 files changed +12
-6
lines changed Expand file tree Collapse file tree 4 files changed +12
-6
lines changed Original file line number Diff line number Diff line change 11from typing import Iterable , Optional , Type , Union
22
3- from pydantic import BaseModel
3+ from fastapi import APIRouter
4+ from pydantic import BaseModel , ConfigDict
45
56from fastapi_jsonapi .data_typing import TypeModel , TypeSchema
67from fastapi_jsonapi .views import Operation , ViewBase
78
89
910class ResourceData (BaseModel ):
11+ model_config = ConfigDict (
12+ arbitrary_types_allowed = True ,
13+ )
14+
1015 path : Union [str , list [str ]]
16+ router : Optional [APIRouter ]
1117 tags : list [str ]
1218 view : Type [ViewBase ]
1319 model : Type [TypeModel ]
Original file line number Diff line number Diff line change 1414from fastapi_jsonapi .data_typing import TypeModel , TypeSchema
1515from fastapi_jsonapi .querystring import QueryStringManager
1616from fastapi_jsonapi .schema import BaseJSONAPIItemInSchema
17+ from fastapi_jsonapi .storages import models_storage
1718from fastapi_jsonapi .views import RelationshipRequestInfo
1819
1920
@@ -51,6 +52,7 @@ def __init__(
5152 self .disable_collection_count : bool = disable_collection_count
5253 self .default_collection_count : int = default_collection_count
5354 self .is_atomic = False
55+ self .id_column_name = models_storage .get_model_id_field_name (resource_type )
5456
5557 async def atomic_start (self , previous_dl : Optional ["BaseDataLayer" ] = None ):
5658 self .is_atomic = True
Original file line number Diff line number Diff line change 1111from fastapi_jsonapi .data_layers .sqla .query_building import RelationshipInfo
1212from fastapi_jsonapi .data_typing import TypeModel
1313from fastapi_jsonapi .exceptions import BadRequest , InternalServerError , ObjectNotFound
14- from fastapi_jsonapi .storages .models_storage import models_storage
1514
1615log = logging .getLogger (__name__ )
1716
@@ -98,10 +97,9 @@ async def count(
9897 cls ,
9998 session : AsyncSession ,
10099 stmt : Select ,
101- resource_type : str ,
100+ id_field_name : str = "id" ,
102101 ) -> int :
103- id_col = models_storage .get_model_id_field_name (resource_type )
104- stmt = select (func .count (distinct (column (id_col )))).select_from (stmt .subquery ())
102+ stmt = select (func .count (distinct (column (id_field_name )))).select_from (stmt .subquery ())
105103 return (await session .execute (stmt )).scalar_one ()
106104
107105 @classmethod
Original file line number Diff line number Diff line change @@ -428,7 +428,7 @@ async def get_collection(
428428 objects_count = await self ._base_sql .count (
429429 session = self .session ,
430430 stmt = query ,
431- resource_type = self .resource_type ,
431+ id_field_name = self .id_column_name ,
432432 )
433433
434434 collection = await self .after_get_collection (collection , qs , view_kwargs )
You can’t perform that action at this time.
0 commit comments