Skip to content

[2.4.0-beta1]: POST with self referencing inclusion returns null values (or default) in included entity  #343

Closed
@milosloub

Description

@milosloub

I have entity Client like this:

public class Client : Identifiable
    {
        [Attr("firstName")]
        public string FirstName  { get; set; }

        [Attr("lastName")]
        public string LastName  { get; set; }

        //[HasOne("advisor", Link.None)]
        //public Advisor Advisor { get; set; }
        //public int AdvisorId { get; set; }

        [HasOne("recommender", Link.None)]
        public Client Recommender { get; set; }
        public int? RecommenderId { get; set; }
    }

Trying to post like:
POST: http://localhost:5001/api/clients?include=recommender

{  
   "data":{  
      "type":"clients",
      "attributes":{  
         "firstName":"Mike",
         "lastName":"Razor"
      },
      "relationships":{  
         "recommender":{  
            "data":{  
               "type":"clients",
               "id":"1"
            }
         }
      }
   }
}

It returns:

{  
   "data":{  
      "attributes":{  
         "firstName":"Mike",
         "lastName":"Razor"
      },
      "relationships":{  
         "recommender":{  
            "data":{  
               "type":"clients",
               "id":"1"
            }
         }
      },
      "type":"clients",
      "id":"2"
   },
   "included":[  
      {  
         "attributes":{  
            "firstName":null,  // <--- This should be not null
            "lastName":null   // <--- This should be not null
         },
         "relationships":{  
            "recommender":{}
         },
         "type":"clients",
         "id":"1"
      }
   ]
}

This is caused only when there is self referencing inclusion (client include another client).
When I change POST with entity of another type (commented Advisor for example), POST with inclusion returns all data normally.

In version 2.3.1 it works fine. 2.3.2 and above has this problem

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions