Hi :wave: I want to get the count using relational...
# orm-help
i
Hi 👋 I want to get the count using relational query :
_await prisma.model.count_({
      
_select_:_ _{
        
_id_: _true_,
        
_user_:_ _{
          
_select_:_ _{
            
_username_: _true_,
_          _},
_        _},
        
_category_:_ _{
          
_select_:_ _{
            
_name_: _true_,
_          _},
_        _},
_      _})
As we already knew that currently its not possible to use select and include at the same time. So I came through another approach without using the include keyword and just directly create a nested object on the field you had a relation with like in my case its user and category. The above query is working fine on .findMany() but it fails on .count(). it throws the error above : _Unknown field
user
for select statement on model PostCountAggregateOutputType. Available options are listed in green. Did you mean
user_id
?_
r
@Ibad Shaikh
count
only returns the count for the given model as a number. It cannot return any fields or relations.