Showing results for 
Search instead for 
Did you mean: 

Integration object creation with one to one relation with same item type.

0 Kudos

I need to create integration object where product has an attribute called relatedProduct with 1-1 relation.
Product- A has relatedProduct B and I want to save the reference of B into A.


Reference to B is not a mandatory field, but when there is value, its suppose to create FK relation.

When I try to save the object I get an error saying
Key attribute 'Product.relatedProduct' forms a circular reference back to 'Product'.
How can I create a integration object in this situation?

View Entire Topic
0 Kudos

The problem is that you marked "relatedProduct" attribute as 'unique' (a key). If you change that to "unique=false", the integration object should be created.

The problem why circular references are not allowed in key attributes is because that makes an infinite loop for key attributes definition and the key attributes (where unique=true) are used for the item search. Imagine this:

there is a Product A with code 'a' and relatedProduct being Product B with code 'b' and relatedProduct being Product A. Let's say integration API processes a POST payload for Product A and needs to find an existing product by its key. It builds the key `code='a' AND relatedProduct=Product B`, but for the search the key cannot contain complex types, i.e. Product B, and should be flattened to primitives only (that's what the database contains), so in reality the key is `code='a' AND relatedProduct.code='b' AND relatedProduct.relatedProduct.code='a' AND relatedProduct.relatedProduct.relatedProduct.code='b'.....`

For comparison, this is how a typical Product key looks based on the Product unique attributes defined in the type system (items.xml): `code = 'a' AND catalogVersion.version = 'Staged' AND = 'Default'`

Note, Product has two unique attribute "code:String" and "catalogVersion:CatalogVersion". CatalogVersion also has two unique attributes : "version:String" and "catalog:Catalog"; and finally Catalog has only one key attribute "id". You can see how these relationships are flattened into a search key in the expression above.

Hope this clarifies.

0 Kudos
Thank you Slava for the reply. I have found that issue was with another attribute at product level which was set as unique, setting that false has resolved the issue.