-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bi-directional references #260
Comments
A few points:
As far as the evitaLab is concerned, if all needed data are on both sides of the bi-di. reference schema, the evitaLab would just render a reference for both entities. The only think that comes to mind is to render flag |
Reaction to those points:
@Reference(
name = REFERENCE_PARAMETER,
faceted = true,
indexed = true
)
@Nonnull
PublishedParameterValueToParameter getParameter() throws ContextMissingException;
@BiDirectionalReference(
name = REFERENCE_PARAMETER_VALUE,
targetRelationName = REFERENCE_PARAMETER
)
@Nonnull
List<PublishedParameterToParameterValue> getParameterValues() throws ContextMissingException;
|
We will also have to introduce something like Hence there is difference between:
The relation can be defined from both places, but it needs to always represent a precedessor order using product ids to declare the chain. In current state of indexes this is not possible because the indexes of specific entity always index primary keys of this |
After recent discussion with FE team using evitaDB, there may be use case were we want to fetch entity that has existing referenced entities of some type. On top of that however, we want to fetch count of these referenced entities without actually fetching the entities.
I think it could be solved also with facet summary, probably like this:
But that's quite cumbersome to use on FE. @novoj do you think it would be valid to support the first approach at the GraphQL API level? We could also reuse the |
Interesting idea - the problem is not only in the query language but also in the output DTOs. We would have to have a new information in the Note: I also found out that the |
And we'd need to also support price constraints nested inside |
I'm reconsidering the original proposal and want to simplify it a bit. A new model for By default, The Definition from the Java prospective will look like: @Reference(
name = "parameter",
faceted = true,
indexed = true
)
@Nonnull
PublishedParameterValueToParameter getParameter() throws ContextMissingException; Parameter type will define reference @Reference(
name = "parameterValues",
entity="parameterValue",
faceted = false
)
@ReflectsReference(
ofName = "parameter",
inheritsAttributes=true,
inheritsAttributesExcept=["a","b"]
)
@Nonnull
List<PublishedParameterToParameterValue> getParameterValues() throws ContextMissingException; This setup will allow you to define exactly what to inherit and what not to inherit. But the simplest form of: @Reference(name = "parameterValues", entity="parameterValue",)
@ReflectsReference(ofName = "parameter")
@Nonnull
List<PublishedParameterToParameterValue> getParameterValues() throws ContextMissingException; will simply inherit all the properties of the original (reflected) reference except its name. (which the developer will probably always want to redefine.) The reference can be updated (upserted/removed) from either location (even as a reflected reference), but the data is always updated in the primary data source, i.e., the reflected primary reference. If the reflected reference doesn't use/inherit the mandatory reference attribute, and the new reference is upserted from the perspective of the reflected reference, the upsert will fail unless the default value for the attribute is defined in the primary reference schema. |
@lukashornych #260 (comment) comment was moved to separate issue #650 |
Basic implementation of the reflected reference schema support in entity schemas with tests.
Basic functionality with test implemented. To be done:
|
feat(#260): bi-directional references, referenced entity predecessors
In certain situations we want to specify relations from the perspective of one entity, but allow them to be used (filtered / ordered by) from the other entity. Example situation:
ParameterValue relates to Parameter entity with cardinality EXACTLY_ONE.
But this relationship can also be seen from the opposite side as
Parameter refers to ParameterValue with cardinality ONE_OR_MORE
There is a 'predecessor' ordering attribute on the relation, which can be set when the ParameterValue entity is inserted, but we want to use it when we fetch related ParameterValues when querying the Parameter entity. So the value of the reference attribute must be synchronised with the value in the ParameterValue reference.
Currently evitaDB only supports unidirectional references and the data and its synchronisation has to be managed by the client application, which is quite problematic and requires additional work. The relational databases have these bidirectional relations "for free".
This would allow certain references to be marked as bi-directional and linked to references specified in different entities. This way the reference will be synchronised by the evitaDB engine on every update. The reference attributes do not have to be shared, but can be. The rules for attribute sharing will be as follows:
If attribute
A
is defined on bi-directional reference in entityX
, attributeA
: may not exist in reference of entityX
.Y
, it must share it's type and other settings.The attribute definition from the other side should be similar to
UseGlobalAttributeSchemaMutation
.The attribute modifications can be made from both sides of the reference and will automatically propagate to indexes in the other entity collection. evitaDB will ensure that the relation is consistent and in-sync from both points of view.
This should noticeably help the client logic to manage the relations consistently.
The text was updated successfully, but these errors were encountered: