Open realnitinworks opened 2 years ago
I've done this manually with a couple of linked SQLAlchemy models and then use the request body to create these models in code. Once the outer model is synced to the DB the linked models will be too.
I've done this manually with a couple of linked SQLAlchemy models and then use the request body to create these models in code. Once the outer model is synced to the DB the linked models will be too.
Could you please elaborate? Are you saying that we need to find our own ways to do this and there is no specific support from flask-restx?
I'm not an expert in flask-restx, but just stating how i've achieved this:
https://github.com/thedumbterminal/ci-speed/blob/main/app/resources/TestRunList.py#L80
In the above example the post handler supports a xml file upload, which builds several linked models, which are written to the db in a single db.commit()
.
Hope this helps.
I have a resource called
Profile
which nests a list ofPort
resources like so:The
profile
key uniquely identifies theProfile
resource and theports
key represents the nested list ofPort
resources. Theport
key in thePort
resource uniquely identifies a port for the givenProfile
.The two Resources are modeled like so:
The skeleton implementation of the two Resources is given below:
Then the routes are as given below:
Question:
When a POST request comes to
/api/v1.0/profiles/<profile>/ports
with the following body:the backend should create the list of
Port
resources for the given profile.Similarly, when a POST request comes to
api/v1.0/profiles
with the following body:Is it possible for the
post
method ofProfile
resource to automatically invoke and reuse thepost
method ofPort
resource passing to it theprofile
which uniquely identifies theProfile
resource? If so, do I need to write my own code or the framework has the capability to handle this?