mirror of
https://github.com/strapi/strapi.git
synced 2025-11-01 18:33:55 +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 {
|
||||
connect: toIdArray(data?.connect),
|
||||
connect: toIdArray(data?.connect).map((elm) => ({
|
||||
id: elm.id,
|
||||
position: elm.position ? elm.position : { end: true },
|
||||
})),
|
||||
disconnect: toIdArray(data?.disconnect),
|
||||
};
|
||||
};
|
||||
@ -834,7 +837,11 @@ const createEntityManager = (db) => {
|
||||
.where({
|
||||
[joinColumn.name]: id,
|
||||
[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)
|
||||
|
||||
@ -19,17 +19,17 @@ class FractionalOrderer {
|
||||
_updateRelationOrder(r) {
|
||||
let idx;
|
||||
// TODO: Throw if the relation does not exist
|
||||
if (r.before) {
|
||||
const { idx: _idx, relation } = this.findRelation(r.before);
|
||||
if (r.position.before) {
|
||||
const { idx: _idx, relation } = this.findRelation(r.position.before);
|
||||
if (relation.init) r.order = relation.order - 0.5;
|
||||
else r.order = relation.order;
|
||||
idx = _idx;
|
||||
} else if (r.after) {
|
||||
const { idx: _idx, relation } = this.findRelation(r.after);
|
||||
} else if (r.position.after) {
|
||||
const { idx: _idx, relation } = this.findRelation(r.position.after);
|
||||
if (relation.init) r.order = relation.order + 0.5;
|
||||
else r.order = relation.order;
|
||||
idx = _idx + 1;
|
||||
} else if (r.start) {
|
||||
} else if (r.position.start) {
|
||||
r.order = 0.5;
|
||||
idx = 0;
|
||||
} else {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user