2 weeks ago - last edited 2 weeks ago
I need to create integration object where product has an attribute called relatedProduct with 1-1 relation.
Example:
Product- A has relatedProduct B and I want to save the reference of B into A.
Product |
code(unique) |
relatedProduct(Product:code) |
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?
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 catalogVersion.catalog.id = '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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
82 | |
11 | |
10 | |
8 | |
7 | |
6 | |
6 | |
6 | |
5 | |
5 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.