mirror of
https://github.com/directus/directus.git
synced 2026-02-11 17:24:56 -05:00
Move sortField to relationship setup (#4304)
* Add migration * Add sort field to relation types * Remove sortfield options in favor of relationship * Add sort field configuration to relational setup * Save m2a sortfield on the correct row * Add default sort field to system data
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
import Knex from 'knex';
|
||||
|
||||
export async function up(knex: Knex) {
|
||||
await knex.schema.alterTable('directus_relations', (table) => {
|
||||
table.string('sort_field');
|
||||
});
|
||||
|
||||
const fieldsWithSort = await knex
|
||||
.select('collection', 'field', 'options')
|
||||
.from('directus_fields')
|
||||
.whereIn('interface', ['one-to-many', 'm2a-builder', 'many-to-many']);
|
||||
|
||||
for (const field of fieldsWithSort) {
|
||||
const options = typeof field.options === 'string' ? JSON.parse(field.options) : field.options ?? {};
|
||||
|
||||
if ('sortField' in options) {
|
||||
await knex('directus_relations')
|
||||
.update({
|
||||
sort_field: options.sortField,
|
||||
})
|
||||
.where({
|
||||
one_collection: field.collection,
|
||||
one_field: field.field,
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export async function down(knex: Knex) {
|
||||
await knex.schema.alterTable('directus_relations', (table) => {
|
||||
table.dropColumn('sort_field');
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user