Added getLabelRelations to Member Model

refs https://github.com/TryGhost/Team/issues/946

In order to bulk remove relations between members and labels we need a
way to get hold of all of the existing relations between a label and a
set of members.
This commit is contained in:
Fabien O'Carroll 2021-08-13 14:17:21 +02:00
parent 2f33292600
commit 1835c22f3b

View File

@ -328,6 +328,19 @@ const Member = ghostBookshelf.Model.extend({
}); });
} }
return ghostBookshelf.Model.destroy.call(this, unfilteredOptions); return ghostBookshelf.Model.destroy.call(this, unfilteredOptions);
},
getLabelRelations(data, unfilteredOptions = {}) {
const query = ghostBookshelf.knex('members_labels')
.select('id')
.where('label_id', data.labelId)
.whereIn('member_id', data.memberIds);
if (unfilteredOptions.transacting) {
query.transacting(unfilteredOptions.transacting);
}
return query;
} }
}); });