Coder Social home page Coder Social logo

Sort and function getCriteria about data HOT 11 CLOSED

yiisoft avatar yiisoft commented on July 18, 2024
Sort and function getCriteria

from data.

Comments (11)

roxblnfk avatar roxblnfk commented on July 18, 2024 1

In yii-cycle it's used getOrder instead of getCriteria.

@roxblnfk do you remember why?

yiisoft/yii-cycle#98

from data.

pawelkeska avatar pawelkeska commented on July 18, 2024 1

Ok, thanks for the explanation.
But when we have a sort object with 15 options to sorted data and have to sort by all fileds i think it's not efficient, especially when we make this operation on big data table. Is there any chance to add option which could turn it off ? i think i some cases it coluld be useful.

from data.

samdark avatar samdark commented on July 18, 2024

Should it work in that way ?

Yes. Currently it's by design:

  1. Read explicitly specified order: withOrder(['descscription' => 'asc'])
  2. Appy it (['id_2' => 'asc', 'title_2' => 'desc']).
  3. Apply defaults for fields not specified. In our case it's title and default is desc: ['first_name' => 'desc', 'title' => 'asc'].

The reasoning is that these interfaces are usually used for grids and not specifying sorting for a field in SQL gives non-predictable sorting (according to how it's stored in DB) but in general we want the sorting to be predictable.

I've checked how it works in yii2 and sort doesn't return rest sorting options by default value.

Yes, in Yii 2 it was different.

In yii-cycle it's used getOrder instead of getCriteria.

@roxblnfk do you remember why?

Could someone explain me how can i create order query in my Doctrine Reader by using this class Sort.

We haven't done any Doctrine integration yet. Maybe someone from Yii community.

from data.

samdark avatar samdark commented on July 18, 2024

Could be useful, indeed.

from data.

samdark avatar samdark commented on July 18, 2024

An option like withoutDefaultSorting() should be alright.

from data.

pawelkeska avatar pawelkeska commented on July 18, 2024

Yes. In my opinion it's alright.
But we could add option to filed sorted like together/join/with and when config is being built in constructor, default option set to false. In this case we can still use all sorts together. Perhaps it's a bit magical but more flexaible.

'title' => [
  'asc' => ['title' => 'asc', 'content' => 'desc'],
  'desc' => ['id' => 'desc', 'title' => 'asc'],
  'default' => 'desc',
  'together/join/with' => true
]

from data.

samdark avatar samdark commented on July 18, 2024

Something like apply with values APPLY_ALWAYS, APPLY_IF_SPECIFIED?

from data.

pawelkeska avatar pawelkeska commented on July 18, 2024

Yes, something like that. It's good idea.

from data.

pawelkeska avatar pawelkeska commented on July 18, 2024

In constructor Sort class maybe add this option like false if we need that it should be added always, change option together/join/with to true (like in example in prev post).

/** @psalm-var TConfig $fieldConfig */
$normalizedConfig[$fieldName] = array_merge([
  'asc' => [$fieldName => SORT_ASC],
  'desc' => [$fieldName => SORT_DESC],
  'default' => 'asc',
  'together/join/with' => true
], $fieldConfig);

and in getCriteria function check it. If this option is to true add to criteria (default always will be false).

foreach ($config as $field => $fieldConfig) {
 if($fieldConfig['together/join/with'])
    $criteria += $fieldConfig[$fieldConfig['default']];
}

from data.

pawelkeska avatar pawelkeska commented on July 18, 2024

i don't know is that correctly solution but i pushed it to my fork.

pawelkeska@dee88c9

from data.

samdark avatar samdark commented on July 18, 2024

I've left some comments.

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.