question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Support for many-to-many associations

See original GitHub issue

Is your feature request related to a problem? Please describe.

I am currently unable to create an association using a $links segment for a many-to-many association, using the API Proxy and API Product resources of SAP API Management. It requires a POST to the $batch endpoint of the service (there are some examples in the Batch Requests section of the API Proxy resource on API Business Hub).

Describe the solution you’d like

I would like to be able to build the correct URL using asChildOf, as it allows me to address the specific record and not the entire entity (e.g. /APIProducts(‘Federated_API’) vs. /APIProducts). However, asChildOf requires me to pass the navigation field (e.g. apiProxiesApi.schema.API_PRODUCTS), which does not include the required $links segment.

Ideally, SAP Cloud SDK would identify this is a many-to-many association from the model metadata and automatically build the URL:

<NavigationProperty Name="apiProducts" Relationship="apiportal.APIProxy_APIProduct_Many_Many0" FromRole="APIProxy" ToRole="APIProduct"></NavigationProperty>

However, it would also be acceptable to pass this leading segment as an additional property to the asChildOf method as a workaround.

Describe alternatives you’ve considered I have tried many combinations of asChildOf, appendPath, Deep Create, etc. without any luck. My only other recourse is to use an external library but I would lose the benefits of destination support and the conciseness of the fluent API.

Impact / Priority

Affected development phase: Release

Impact: Blocked

Timeline: Release scheduled for Q4 2022

Additional context This is part of a code sample showing customers how to federate API documentation between different gateways (both SAP and Non-SAP) for a unified API catalog. It reacts to an inbound event, fetches the Open API spec programmatically from another provider, and creates a Remote API in SAP API Management.

Here is a complete sample payload for the batch call:

--batch_b2fe-fc86-d733
Content-Type: multipart/mixed; boundary=changeset_dbf2-c5bb-a344

--changeset_dbf2-c5bb-a344
Content-Type: application/http
Content-Transfer-Encoding: binary

PUT APIProducts(name='SimplifiedS4HANAProducts') HTTP/1.1
x-csrf-token: d776c7a92458b493-_X7FJI30ncQz7nl3UV0xvW856cU
Accept-Language: en
Accept: application/json
MaxDataServiceVersion: 2.0
DataServiceVersion: 2.0
Content-Type: application/json
Content-Length: 249

{"name":"SimplifiedS4HANAProducts","title":"Simplified S/4HANA Product API","scope":"","description":"<p></p>","version":"1","status_code":"PUBLISHED","isRestricted":false,"isPublished":true,"quotaCount":-99,"quotaInterval":-99,"quotaTimeUnit":null}
--changeset_dbf2-c5bb-a344
Content-Type: application/http
Content-Transfer-Encoding: binary

POST APIProducts(name='SimplifiedS4HANAProducts')/$links/apiProxies HTTP/1.1
x-csrf-token: d776c7a92458b493-_X7FJI30ncQz7nl3UV0xvW856cU
Accept-Language: en
Accept: application/json
MaxDataServiceVersion: 2.0
DataServiceVersion: 2.0
Content-Type: application/json
Content-Length: 32

{"uri":"APIProxies('Ping_CPI')"}
--changeset_dbf2-c5bb-a344
Content-Type: application/http
Content-Transfer-Encoding: binary

POST APIProxies(name='Ping_CPI')/$links/apiProducts HTTP/1.1
x-csrf-token: d776c7a92458b493-_X7FJI30ncQz7nl3UV0xvW856cU
Accept-Language: en
Accept: application/json
MaxDataServiceVersion: 2.0
DataServiceVersion: 2.0
Content-Type: application/json
Content-Length: 49

{"uri":"APIProducts('SimplifiedS4HANAProducts')"}
--changeset_dbf2-c5bb-a344--

--batch_b2fe-fc86-d733--

Issue Analytics

  • State:open
  • Created a year ago
  • Reactions:2
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

3reactions
jmsrppcommented, Nov 2, 2022

Hi @jjtang1985 @marikaner - Thanks for the follow up on this issue. I was able to get it working as it seems appendPath can be used to append anything and not just paths. I eliminated asChildOf and added something like:

.appendPath((name='Federated_API'), ‘/$links’, ‘/apiProxies’);

or

.appendPath((name='${proxyName}'), ‘/$links’, ‘/apiProducts’);

to the requestBuilder() calls for each entity. I also had to add ‘as any’ to the create() and changeset() calls to prevent compilation errors. Even though it is less than ideal, I can utilize this as a workaround in Q4 while you finalize an ADR and plan for type-safe support in the future.

2reactions
jjtang1985commented, Nov 3, 2022

Hi @jmsrpp ,

Awesome. I’m happy to see it’s working with the workaround. Thanks for sharing your examples.

To answer your question:

What is .stringProperty method of the entity builder? I could not find it in the documentation.

The stringProperty is just a normal property of our test entity like any known properties of ApiProxies defined in the specification file in your case.

I’ll leave this ticket open and update later.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Best Practices for Many-to-Many Associations with Hibernate ...
Many-to-Many associations are very popular with JPA and Hibernate. Follow these best practices to avoid common pitfalls and create efficient mappings.
Read more >
Synchronization Methods for Many-To-Many Associations
This article will highlight common issues that happen when adding synchronized methods for many-to-many bidirectional associations in JPA ...
Read more >
Data Modelling: Many-to-Many Association - Jmix
The many-to-many association implies that multiple records of one table are related to multiple records of another table. The joining table will store...
Read more >
Advanced M:N Associations | Sequelize
The simplest way to define the Many-to-Many relationship is: ... Sequelize supports self-referential Many-to-Many relationships, intuitively: Person.
Read more >
Many to many associations - JavaLite
Often times the database-driven applications require many to many relationships. These are the kind where an entity can have many other entities and...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found