igorbenav / fastcrud

FastCRUD is a Python package for FastAPI, offering robust async CRUD operations and flexible endpoint creation utilities.
MIT License
693 stars 59 forks source link

Join list of objects #121

Open JakNowy opened 4 months ago

JakNowy commented 4 months ago

Is your feature request related to a problem? Please describe. For OneToMany relationships, using get_joined or get_multi_joined returns one nested object, while in some cases I'd like to return all related objects.

Describe the solution you'd like fastcrud.get_joined_list(...) ->

{
    "id": 1,
    "joined_objects": [
        {
            "id":1
            "name": Donald,
        },
        {
            "id":2
            "name": Joe,
        },
    ]
}
igorbenav commented 4 months ago

Can you please send code to reproduce and output?

JakNowy commented 3 months ago

What I exactly mean here is to introduce fastcrud.get_joined_many() method which would return an object with a list of relationships.

So on top of existing fastcrud.get_joined() ->

{
    "id": 1,
    "joined_object": {   # just 1 relationship object
            "id":1
            "name": Donald,
        }
}

we add fastcrud.get_joined_many() ->

{
    "id": 1,
    "joined_objects": [    # multiple relationship objects
        {
            "id":1
            "name": Donald,
        },
        {
            "id":2
            "name": Joe,
        },
    ]
}

Does it make sense to you to add such feature or it's too compllicated?

neatek commented 2 months ago

Maybe its about relationship_type?

relationship_type: Specifies the relationship type, such as "one-to-one" or "one-to-many". Default is "one-to-one". https://igorbenav.github.io/fastcrud/advanced/joins/#handling-one-to-one-and-one-to-many-joins-in-fastcrud https://igorbenav.github.io/fastcrud/advanced/joins/#one-to-many-relationships https://igorbenav.github.io/fastcrud/advanced/joins/#many-to-many-relationships-with-get_multi_joined