mirror of
https://github.com/directus/directus.git
synced 2026-01-31 15:57:57 -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');
|
||||
});
|
||||
}
|
||||
@@ -8,6 +8,7 @@ defaults:
|
||||
one_field: null
|
||||
one_primary: null
|
||||
junction_field: null
|
||||
sort_field: null
|
||||
|
||||
data:
|
||||
- many_collection: directus_users
|
||||
|
||||
@@ -11,4 +11,7 @@ export type Relation = {
|
||||
|
||||
one_collection_field: string | null;
|
||||
one_allowed_collections: string | null;
|
||||
|
||||
junction_field: string | null;
|
||||
sort_field: string | null;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user