Skip to content

[BUG] Opposite relationships defined in DocumentDB are handled as simple relationships #67

@meuriceloup

Description

@meuriceloup

Hi,

This is the deployed TML schema:

entity Product {
    id : String
    orders -> Order[1]
}
entity Order {
    id : String
    products -> Product."Product.orders"[1]
}

documentdb DocumentDatabase {
	collections {
		Order : Order
		Product : Product
	}
}

In this schema, there are two defined entities declared in the documentdb. In addition, a 1-1 opposite relationship is defined between both entities. However, it seems that the polystore handles this opposite relationship as two simple unrelated relationships.
Scenario:

  1. I executed this insert statement:
    insert Product {id: "p", orders: Order {id: "o"}}
  2. I secondly executed this one (in the inverse sense):
    insert Order {id:"o2", products: Product {id: "p2"}}
  3. I executed this select query:
    from Product p, Order o select p, o where p.orders == o

However, it only returns this:

(
  "Order":[<"Order","6a7fb7d1-ed40-4f72-838b-7a3077f4b8ad",("id":"o")>],
  "Product":[<"Product","162f73d2-ea92-4437-a6aa-e9deb00b0947",(
      "orders":<true,"6a7fb7d1-ed40-4f72-838b-7a3077f4b8ad">,
      "id":"p"
    )>]
)

it was supposed to return (o2, p2) as well, since an opposite relationship is defined. For obtaining the complete results: I had to execute this QL query:

from Product p, Order o select p, o where o.products == p || p.orders == o

I then took a look at the MongoDB structures and the stored data and, indeed, the opposite relationship seems to be handled as two different relationships...
This is what the MongoDB looks:

image
image

In first image, field 'Order.product' is used to store relationship (o2, p2).
In second image, field 'Product.orders' is used to store relationship (o,p).

This way to handle the opposite relation seems equivalent to handling two different relationships and it causes the incomplete results when executing this QL query:
from Product p, Order o select p, o where p.orders == o

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions