question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Creating nested object

See original GitHub issue

Is there a way I can create a nested object without passing the ID of the parent?

e.g

POST /domains/1/nameservers
{
  domain: 1, # -> I don't want to pass this in the request
  <nameserver data>
}

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:7 (1 by maintainers)

github_iconTop GitHub Comments

4reactions
areebbeighcommented, Aug 31, 2020
class NameserverViewset(viewsets.ModelViewSet):
    (...)
    def perform_create(self, serializer):
        serializer.save(user=self.request.user, domain_id=self.kwargs['domain_pk'])

is what I was looking for 😛 thanks.

0reactions
nrjcommented, Sep 9, 2021

Since this is somewhat related, is there a recommended way to perform validation of the parent primary key in the URL?

With the above solution, making a POST to say /domains/999/nameservers/ will raise if there is no domain with id=999

Where would it be best to handle this Exception?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Creating Nested Objects in JavaScript Dynamically - LinkedIn
Dynamic creation of a nested object means that we don't know the properties of the object when we initialize it and even these...
Read more >
Nested objects in javascript, best practices - Stack Overflow
I would like to know the correct way to create a nested object in javascript. I want a base object called "defaultsettings".
Read more >
How to use Nested Objects in JavaScript - Linux Hint
In JavaScript, nested objects are used to store the properties of an object in another object. These objects are accessible via dot or...
Read more >
Nested Objects - Learn JavaScript - Codecademy
In application code, objects are often nested— an object might have another object as a property which in turn could have a property...
Read more >
Constructing a nested JSON object in JavaScript - Tutorialspoint
Constructing a nested JSON object in JavaScript - We have a special kind of string that contains characters in couple, like this −const...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found