joukevandermaas / saule

JSON API library for ASP.Net Web API 2.
https://joukevandermaas.github.io/saule
MIT License
76 stars 37 forks source link

Saule does not add data [attributes] in relationships, I am using visual studio 2013 Community Edition #119

Closed dhirajdhakal09 closed 8 years ago

dhirajdhakal09 commented 8 years ago

Hi,

I want to return a compound element having data other than links in the relationships field. But I cannot able to do so, I updated Saule to current 1.5 beta version but that din't help out too.

I tried with many approaches described in this blog but none of them works. I even did with the same model and resource provided in the wiki but that din't help out too.

This is my model, I want to have the data of the Plan object when trying to invoke the Number Resources, but at the moment only link is returned.

public class Number { public Guid? Id { get; set; } public string Number {get; set; } public Plan plan {get; set; } } public class Plan { public Guid? Id {get; set;} public string Description {get;set;} }

And this is my resources:

public class NumberResource : ApiResource { public NumberResource() { OfType("numbers"); Attribute("Number");

    BelongsTo<PlanResource >("plans");
}

}

public class PlanResource : ApiResource { public PlanResource() { OfType("plans"); Attribute("Description"); }

}

This is how I initialized the number.

var myNumber = new Number { Id = new Guid(), Number = "12345", Plan = new Plan { Id = new Guid(), Description = "Some Description" } };

And the result is always as follows, it has relationships field but no data on it.

{ "data": [ { "type": "numbers", "id": "00000000-0000-0000-0000-000000000000", "attributes": { "number": "12345",

}, "relationships": {

"plans": {
  "links": {
    "self": "http://localhost:58739/api/numbers/00000000-0000-0000-0000-000000000000/relationships/plans/",
    "related": "http://localhost:58739/api/numbers/00000000-0000-0000-0000-000000000000/plans/"
  }
}

}, "links": { "self": "http://localhost:58739/api/numbers/00000000-0000-0000-0000-000000000000/" } } ], "links": { "self": "http://localhost:58739/api/numbers" } }

I would rather expect

"relationships": {

"plans": {
  "links": {
    "self": "http://localhost:58739/api/numbers/00000000-0000-0000-0000-000000000000/relationships/plans/",
    "related": "http://localhost:58739/api/numbers/00000000-0000-0000-0000-000000000000/plans/"
  },

"data": { "type": "plans", "description": "sth" } }

Did I miss anything in here, or saule works as expected on Visual Studio 2015?

Please let me know.

Thanks!!

dhirajdhakal09 commented 8 years ago

Finally installed VS 2015 and dug into the code and found out the way to retrieve the included members. To pull it off we need to give the same name of the relationship property to the relationship model. Hope it helps someone.