update options
This commit is contained in:
parent
f6f8f041f1
commit
30e31a2e79
@ -13,7 +13,9 @@ describe('array field operator', function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
db = mockDatabase();
|
db = mockDatabase({
|
||||||
|
logging: console.log,
|
||||||
|
});
|
||||||
|
|
||||||
Test = db.collection({
|
Test = db.collection({
|
||||||
name: 'test',
|
name: 'test',
|
||||||
@ -43,45 +45,40 @@ describe('array field operator', function () {
|
|||||||
test('array field update', async () => {
|
test('array field update', async () => {
|
||||||
const Post = db.collection({
|
const Post = db.collection({
|
||||||
name: 'posts',
|
name: 'posts',
|
||||||
fields: [
|
fields: [{ type: 'array', name: 'tags' }],
|
||||||
{ type: 'array', name: 'tags' },
|
|
||||||
],
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
await db.sync({ force: true });
|
||||||
|
|
||||||
await db.sync({force: true})
|
await Post.repository.create({});
|
||||||
|
|
||||||
await Post.repository.create({})
|
|
||||||
const p1 = await Post.repository.create({
|
const p1 = await Post.repository.create({
|
||||||
values: {
|
values: {
|
||||||
tags: ['t1', 't2']
|
tags: ['t1', 't2'],
|
||||||
}
|
},
|
||||||
})
|
});
|
||||||
|
|
||||||
|
|
||||||
let result = await Post.repository.findOne({
|
let result = await Post.repository.findOne({
|
||||||
filter: {
|
filter: {
|
||||||
'tags.$match': ['t2', 't1']
|
'tags.$match': ['t2', 't1'],
|
||||||
}
|
},
|
||||||
})
|
});
|
||||||
|
|
||||||
expect(result.get('id')).toEqual(p1.get('id'))
|
expect(result.get('id')).toEqual(p1.get('id'));
|
||||||
|
|
||||||
await Post.repository.update({
|
await Post.repository.update({
|
||||||
filterByPk: <number>p1.get('id'),
|
filterByPk: <any>p1.get('id'),
|
||||||
values: {
|
values: {
|
||||||
tags: ['t3', 't2']
|
tags: ['t3', 't2'],
|
||||||
}
|
},
|
||||||
})
|
});
|
||||||
|
|
||||||
result = await Post.repository.findOne({
|
result = await Post.repository.findOne({
|
||||||
filter: {
|
filter: {
|
||||||
'tags.$match': ['t3', 't2']
|
'tags.$match': ['t3', 't2'],
|
||||||
}
|
},
|
||||||
})
|
});
|
||||||
|
|
||||||
|
expect(result.get('id')).toEqual(p1.get('id'));
|
||||||
expect(result.get('id')).toEqual(p1.get('id'))
|
|
||||||
});
|
});
|
||||||
|
|
||||||
test('nested array field', async () => {
|
test('nested array field', async () => {
|
||||||
|
@ -12,7 +12,6 @@ export class ArrayField extends Field {
|
|||||||
|
|
||||||
sortValue(model) {
|
sortValue(model) {
|
||||||
const oldValue = model.get(this.options.name);
|
const oldValue = model.get(this.options.name);
|
||||||
console.log({oldValue})
|
|
||||||
if (oldValue) {
|
if (oldValue) {
|
||||||
const newValue = oldValue.sort();
|
const newValue = oldValue.sort();
|
||||||
model.set(this.options.name, newValue);
|
model.set(this.options.name, newValue);
|
||||||
@ -21,9 +20,7 @@ export class ArrayField extends Field {
|
|||||||
|
|
||||||
bind() {
|
bind() {
|
||||||
super.bind();
|
super.bind();
|
||||||
|
|
||||||
this.on('beforeSave', this.sortValue.bind(this));
|
this.on('beforeSave', this.sortValue.bind(this));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
unbind() {
|
unbind() {
|
||||||
|
@ -108,7 +108,7 @@ export interface CreateOptions extends SequelizeCreateOptions {
|
|||||||
context?: any;
|
context?: any;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface UpdateOptions extends SequelizeUpdateOptions {
|
export interface UpdateOptions extends Omit<SequelizeUpdateOptions, 'where'> {
|
||||||
values: Values;
|
values: Values;
|
||||||
filter?: Filter;
|
filter?: Filter;
|
||||||
filterByPk?: PrimaryKey;
|
filterByPk?: PrimaryKey;
|
||||||
|
Loading…
Reference in New Issue
Block a user