Can't I use .values() with relationships?
See original GitHub issueTake the following example :
class Task(Model):
title = fields.CharField(255)
class Actions(Model):
title = fields.CharField(255)
task = fields.ManyToManyField('models.Task', related_name='actions')
async def main():
tasks = await Task.all().prefetch_related('actions').values('actions')
I’m trying to achieve the following structure:
[
{
"id" : 1,
"title" : "Task 1",
"actions" : [
{
"id" : 1,
"title" : "Action 1"
}
]
}
]
But it gives me Selecting relation "actions" is not possible, select concrete field on related model
Is this intended? Do I need to use a serializer to be able to achieve this structure?
How would I choose to return only specific fields from actions
if not using values
?
Issue Analytics
- State:
- Created 4 years ago
- Comments:11 (7 by maintainers)
Top Results From Across the Web
Values in a Relationship: 8 Core Values for Relationships - 2022
1. Communication: Keeping open lines of communication with your partner can set you up to having a successful relationship. · 2. Equality: Seeing ......
Read more >10 Core Values of a Lasting Relationship - Lifehack
1. Trust ... This core value stands above all others. It is the foundation of your relationship. Without trust you basically have nothing....
Read more >Use Relationship column value as property - laravel
I have a one to many relation. They all have a unique column ( besides ID ). After running the query, Im trying...
Read more >Value-based Conditional Relationships - Laracasts
After looking at your table setup, you should be using a belongsTo() method to describe the relationship. The second argument should be the...
Read more >11 Core Relationship Values Every Couple Must Have
For example, marriage core values, such as respect and forgiveness, when shared among partners, can be of immense help in conflict management.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Could we not make it use kwargs? E.g. values(‘name’, childs=Childs.all().values(…)) ? And if you pass a queryset it would auto prefetch?
This would implement a useable deserialisation step 🤔 And be performant
(Generally in favour)
I have idea that it would be quite neat to have such api
That would result in such dict
@grigi What do you think about such design?