GithubHelp home page GithubHelp logo

Comments (3)

DaddyWarbucks avatar DaddyWarbucks commented on May 27, 2024

Also, we likely need to do some more type checking on the $and. Note in this line that we assume the $and is an array. But the code also potentially returns an object instead of an array.

[and]: where[and] ? [...where[and], { [this.id]: id }] : { [this.id]: id }

So if $and works with an object and not just an array, when we need to check that. I think it is most common that its an array so we should also return an array.

Something like

applyAndQuery(where, id) {
  const { and } = this.Op;
  const IdQuery = { [this.id]: id };
  const newWhere = Object.assign({}, where);

  if (!newWhere[and]) {
    newWhere[and] = [IdQuery]
    return newWhere;
  }

  if (Array.isArray(newWhere[and])) {
    newWhere[and] = [...newWhere[and], idQuery];
    return newWhere;
  }

  newWhere[and] = [newWhere[and], idQuery];
  return newWhere;
}

from feathers-sequelize.

fratzinger avatar fratzinger commented on May 27, 2024

Good catch! We should add a test for that. Maybe even on @feathersjs/adapter-tests and we could add $and to the official supported operators list at https://docs.feathersjs.com/api/databases/querying.html.

Op.and and Op.or can be used as an object, indeed (see https://sequelize.org/v6/manual/model-querying-basics.html#examples-with--code-op-and--code--and--code-op-or--code-). But I believe at the root level they're always meant to be arrays. It makes sense if they're nested within a column query like:

where: {
  rank: {
    [Op.and]: {
      [Op.lt]: 1000,
      [Op.eq]: null
    }
  },
}

from feathers-sequelize.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.