yiisoft / yiisoft/active-record

Case insensitive keys for relation models

Open
#22 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
PHP
Stars
119
Forks
38
Avg merge
1h 11m
Merged PRs (30d)
1

Description

What steps will reproduce the problem?
 $dataProvider = new ActiveDataProvider([
            'query' => $query->joinWith(['someCaseInsensitiveRelation']),
        ]);
What is the expected result?

So If I make request without dataProvider, I have got all related models:

2018-11-29_16-44-17

What do you get instead?

but if I using dataProvider related models will be empty

2018-11-29_16-39-51

Additional info

It's happens because model keys case sensitive. For example I using Postgres citext or for MySQL (for utf8) my on condition case insensitive (luke = Luke).

I suggest add optional feature for this. May be useCaseInsensitiveKeys = false or something else? It might looks like:

//vendor/yiisoft/yii2/db/ActiveRelationTrait.php

    private function normalizeModelKey($value)
    {
        if (is_object($value) && method_exists($value, '__toString')) {
            // ensure matching to special objects, which are convertable to string, for cross-DBMS relations, for example: `|MongoId`
            $value = $value->__toString();
        }

        return $this->useCaseInsensitiveKeys ? strtolower($value) : $value;
    }

any suggestions?

Q A
Yii version 2.0.15.1
PHP version 7.0.2
Operating system MacOs 12.4

related to #9077

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in vendor/yiisoft/yii2/db/ActiveRelationTrait.php and reproduce the difference between joinWith('someCaseInsensitiveRelation') through ActiveDataProvider and a direct request. Compare how relation model keys are matched for PostgreSQL citext and case-insensitive MySQL conditions. Done means related models are populated when keys differ only by case, with the opt-in behavior and API agreed.

Written by the indexing model from the issue text.

Assessment

Tech stack
mysql, php, postgresql
Domain
database
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.