mirror of
https://github.com/strapi/strapi.git
synced 2025-11-15 17:49:57 +00:00
use position attribute for positional arguments
This commit is contained in:
parent
485355820f
commit
2e7aa7c2a9
@ -77,7 +77,10 @@ const toAssocs = (data) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
connect: toIdArray(data?.connect),
|
connect: toIdArray(data?.connect).map((elm) => ({
|
||||||
|
id: elm.id,
|
||||||
|
position: elm.position ? elm.position : { end: true },
|
||||||
|
})),
|
||||||
disconnect: toIdArray(data?.disconnect),
|
disconnect: toIdArray(data?.disconnect),
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
@ -834,7 +837,11 @@ const createEntityManager = (db) => {
|
|||||||
.where({
|
.where({
|
||||||
[joinColumn.name]: id,
|
[joinColumn.name]: id,
|
||||||
[inverseJoinColumn.name]: {
|
[inverseJoinColumn.name]: {
|
||||||
$in: compact(cleanRelationData.connect.map((r) => r.after || r.before)),
|
$in: compact(
|
||||||
|
cleanRelationData.connect.map(
|
||||||
|
(r) => r.position?.after || r.position?.before
|
||||||
|
)
|
||||||
|
),
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
.transacting(trx)
|
.transacting(trx)
|
||||||
|
|||||||
@ -19,17 +19,17 @@ class FractionalOrderer {
|
|||||||
_updateRelationOrder(r) {
|
_updateRelationOrder(r) {
|
||||||
let idx;
|
let idx;
|
||||||
// TODO: Throw if the relation does not exist
|
// TODO: Throw if the relation does not exist
|
||||||
if (r.before) {
|
if (r.position.before) {
|
||||||
const { idx: _idx, relation } = this.findRelation(r.before);
|
const { idx: _idx, relation } = this.findRelation(r.position.before);
|
||||||
if (relation.init) r.order = relation.order - 0.5;
|
if (relation.init) r.order = relation.order - 0.5;
|
||||||
else r.order = relation.order;
|
else r.order = relation.order;
|
||||||
idx = _idx;
|
idx = _idx;
|
||||||
} else if (r.after) {
|
} else if (r.position.after) {
|
||||||
const { idx: _idx, relation } = this.findRelation(r.after);
|
const { idx: _idx, relation } = this.findRelation(r.position.after);
|
||||||
if (relation.init) r.order = relation.order + 0.5;
|
if (relation.init) r.order = relation.order + 0.5;
|
||||||
else r.order = relation.order;
|
else r.order = relation.order;
|
||||||
idx = _idx + 1;
|
idx = _idx + 1;
|
||||||
} else if (r.start) {
|
} else if (r.position.start) {
|
||||||
r.order = 0.5;
|
r.order = 0.5;
|
||||||
idx = 0;
|
idx = 0;
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user