Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed serialization bug #34

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

NicholasMiller
Copy link

@NicholasMiller NicholasMiller commented Dec 29, 2016

Fixed an issue where serialization fails if a model contains multiple linked entities of the same type. Take the following simple example:

public class PersonModel
{
    public int Id { get; set; }
    public String FirstName { get; set; }
    public String LastName { get; set; }
}

public class MusicLessonModel
{
    public DateTime Date { get; set; }
    public int TeacherPersonId  { get; set; }
    public PersonModel TeacherPerson { get; set; }
    public int StudentPersonId  { get; set; }
    public PersonModel StudentPerson { get; set; }
}

Assuming the appropriate controllers have been setup, calling http://hostname/music-lessons?include=person results in a 500 response prior to the code change in this pr.

Fixed an issue where serialization fails if a model contains multiple linked entities of the same type.
@NicholasMiller NicholasMiller changed the title Fixed issue serialization bug Fixed serialization bug Dec 29, 2016
@brainwipe
Copy link
Owner

Thanks for the PR! Sorry for the slow reply, a baby has arrived in the house. There's definitely a bug in there but it's not the one you've fixed, so I'm afraid I'm going to reject the PR.

The line:

var relationship = currentMapping.Relationships.SingleOrDefault(x => x.RelatedBaseResourceType == part);

is incorrect because it is matching on the RelatedBaseResourceType. It should be matching on the Name of the resource. Using your example, the request should be:

GET http://hostname/music-lessons?include=teacherperson

As property names are unique, the SingleOrDefault should return a single linked resource.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants