0

I'm using a Spring Data REST backend with AngularJs as frontend. How is the best way to add sub-resources to a "root Entity"?

From official documentation section 4.4.1: http://docs.spring.io/spring-data/rest/docs/2.3.0.RELEASE/reference/html/#repository-resources.search-resource we can POST to association resource using "text/uri-list"

A tipical example of sub-resource are Comments to a BlogPost like this question: POSTing a @OneToMany sub-resource association in Spring Data REST

From Spring documentation I should proceed in two steps:

  1. add the new sub-resource (POST a new Comment)
  2. and then add the link (POST a text/uri-list to the BlogPost comments)
Community
  • 1
  • 1
Mirco Attocchi
  • 776
  • 1
  • 7
  • 14

1 Answers1

0

I don't see the relation with AngularJS : you can either use $http or $resource or halClient to POST your entities.

If you have a bi-directionnal relation between blogpost and comment, it should work just by POSTing the comments with the 'parentBlogPost' field filled. If you get back the blogpost, its comments would be updated automatically.

If you have uni-directionnal relation, then you need to POST the uri-list too.

JR Utily
  • 1,792
  • 1
  • 23
  • 38