chatrli
chatrli
CC#
Created by chatrli on 10/13/2023 in #help
❔ Relationship validation
Here is my controller, feel free to navigate through the repo: https://github.com/chatrli/api_onotebook/blob/emails/Controllers/PeopleController.cs I added a relationship between my Person and Email models. Then I wrote a POST method to add an new email to a person by its id but i always the same error using postman and curl (with this route http://localhost:5062/people/1/emails)
{
"type": "https://tools.ietf.org/html/rfc7231#section-6.5.1",
"title": "One or more validation errors occurred.",
"status": 400,
"traceId": "00-5628679ef1a96e94cb3c5347f4417827-abfa0d432f9b4cbc-00",
"errors": {
"Person": [
"The Person field is required."
]
}
}
{
"type": "https://tools.ietf.org/html/rfc7231#section-6.5.1",
"title": "One or more validation errors occurred.",
"status": 400,
"traceId": "00-5628679ef1a96e94cb3c5347f4417827-abfa0d432f9b4cbc-00",
"errors": {
"Person": [
"The Person field is required."
]
}
}
I don't need the person field to be required actually I want to be able to have Person with no email and just register new email later. There is no Person + Email creation the same time. As I'm new to dotnet and have to be confortable with at least web api soon, I wish I can see how a simple relationship is used through the controller. Else if you have an explanation I will be glad. What I tried so far is making the Person field nullable in the Post method for create email but in comparison of other backend Im working with so far, it feels like a non sense.
c#
email.Person = null;
c#
email.Person = null;
When I said it feels like a non sense I mean that this should not require to be nullable? We should be able to just add a new email without creating a new Person, as on client side, there is 2 form. One for the Person and a second one for the Email that is in Person Detail page.
32 replies