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