@@ -103,17 +103,19 @@ result can be anticipated:
103
103
104
104
</NoteTitle >
105
105
106
- The situation can be more complicated when the reference is one-to-many. What is the expected result of a query that
107
- involves ordering by a property on a reference attribute? Is it wise to allow such ordering query in this case?
106
+ Things can get more complicated when the reference is one-to-many. What should you expect when you run a query that
107
+ involves sorting by a property on a reference attribute? Relational databases allow this, but you need to deal with
108
+ the problem of row multiplication. With evitaDB, you work with an entity model, so you don't have to worry about
109
+ the multiplication problem. It's possible, but there are some specifics because evitaDB supports hierarchical entities.
108
110
109
- We decided to allow it and bind it with the following rules :
111
+ Let's break it down into two cases :
110
112
111
113
** Non-hierarchical entity**
112
114
113
- If the referenced entity is ** non-hierarchical** , and the returned entity references multiple entities, only
114
- the reference with the lowest primary key of the referenced entity, while also having the order property set, will be
115
- used for ordering. This behavior is equivalent as if you used the [ ` pickFirstByEntityProperty ` ] ( #pick-first-by-entity-property )
116
- constraint in your ` referenceProperty ` container:
115
+ If the referenced entity is non-hierarchical and the returned entity references multiple entities, only the reference
116
+ with the lowest primary key of the referenced entity, while also having the order property set, will be used for ordering.
117
+ This is the same as if you had used the [ ` pickFirstByEntityProperty ` ] ( #pick-first-by-entity-property ) constraint in
118
+ your ` referenceProperty ` container:
117
119
118
120
``` evitaql
119
121
pickFirstByEntityProperty(
@@ -127,11 +129,11 @@ If the referenced entity is **hierarchical** and the returned entity references
127
129
for ordering is the one that contains the order property and is the closest hierarchy node to the root of the filtered
128
130
hierarchy node.
129
131
130
- It sounds complicated, but it's really quite simple. If you list products of a certain category and at the same time
131
- order them by a property ` orderInCategory ` set on the reference to the category, the first products will be those
132
- directly related to the category, ordered by ` orderInCategory ` , followed by the products of the first child category,
133
- and so on, maintaining the depth-first order of the category tree. This behavior is equivalent as if you used the
134
- [ ` traverseByEntityProperty ` ] ( #traverse-by-entity-property ) constraint in your ` referenceProperty ` container:
132
+ It sounds complicated, but it's really quite simple. Imagine you're listing products from a category and also sorting
133
+ them by a property called ` orderInCategory ` on the category reference. The first products you get are the ones directly
134
+ related to the category, in order of ` orderInCategory ` . Then you get the products from the first child category, and so
135
+ on, keeping the category tree's order . This is the same as using the [ ` traverseByEntityProperty ` ] ( #traverse-by-entity-property )
136
+ constraint in your ` referenceProperty ` container:
135
137
136
138
``` evitaql
137
139
traverseByEntityProperty(
@@ -142,11 +144,11 @@ traverseByEntityProperty(
142
144
143
145
** Note:**
144
146
145
- You can control the behavior if you explicitly use the ` pickFirstByEntityProperty ` or ` traverseByEntityProperty `
146
- constraints in your ` referenceProperty ` container. The ` traverseByEntityProperty ` can be used also for non-hierarchical
147
- entities and makes sense also for 1:1 references. It changes the ordering so that the entities are sorted by the target
148
- referenced entity property first, and then by the reference property itself. For more information, see the examples and
149
- detailed documentation of the [ ` traverseByEntityProperty ` ] ( #traverse-by-entity-property ) constraint.
147
+ You can control the behaviour by using the ` pickFirstByEntityProperty ` or ` traverseByEntityProperty ` constraints in your
148
+ ` referenceProperty ` container. You can also use the ` traverseByEntityProperty ` for non-hierarchical entities and for 1:1
149
+ references. It changes the order so that the entities are first sorted by the property of the thing they're referring to,
150
+ and then by the reference property itself. For more information, check out the examples and the detailed documentation
151
+ of the [ ` traverseByEntityProperty ` ] constraint.
150
152
151
153
</Note >
152
154
0 commit comments