Coder Social home page Coder Social logo

Comments (6)

pchapl avatar pchapl commented on July 18, 2024 1

There already is "filter to array" transformation in IterableDataReader:

$filter = null;
if ($this->filter !== null) {
    $filter = $this->filter->toArray();
}

Could be replaced with

$filter = $this->filter instanceof FilterInterface
    ? $this->filter->toArray()
    : $this->filter;

So well-formed filter will work properly. But there will be problems with incorrect filters (kind of ['and', 'id', '>']) and will require some extra validation.

UPD:
I thought and IMHO that should not be done.
In Yii2, newbies have always had problems setting conditions for where. Just look at the popularity of the questions "Operator '{operator}' requires {N} operands". And even more experienced often have to google the correct order of operands. When using objects at the same time, the correctness of the constructed $filter array is guaranteed, and the author of the code sees the types and names of constructor parameters so as not to confuse.

from data.

romkatsu avatar romkatsu commented on July 18, 2024 1

@pchapl Yes, objects are better. But it seems here the speech about that there was an opportunity to use arrays.

from data.

samdark avatar samdark commented on July 18, 2024

It is more about working with a special filter string that comes from request like it's done for sorting.

In Yii 2 REST APIs there was ability to specify filtering as JSON.

Requirements are:

  1. It should be as short as possible.
  2. It should be readable.
  3. Some filters could be disabled for some fields (tricky part).

from data.

samdark avatar samdark commented on July 18, 2024

Overall, it can be done with a separate component so could be safely postponed or done in another package such as GridView.

from data.

kamarton avatar kamarton commented on July 18, 2024
$filter = $aaa->where([
  ['and', 'id', '>', 3],
  ['and', ['or', ['temperature', '<', 10], ['temperature', '>', 30]] ],
  ['and', 'name', like', '%agent%'],
];

I would limit the use of this to simplify code.

$filter = new All()->withArray([
  ['<', 'id', 22],
  ['or',
    ['>', 'apple', 33],
    ['!=', 'peach', 44], 
  ]
])

$filter = new Any(
  new All(new Equals(), ...),
  new All()->withArray([...]),
)

Arrays would be limited to the All class, this method would allow all kinds of use. The All class is working on arrays, so much easier code is created.

from data.

samdark avatar samdark commented on July 18, 2024

All or Any. Yes, good idea.

from data.

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.