Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hasOne or hasMany return null when $link with two bigint element #20124

Open
easydowork opened this issue Mar 6, 2024 · 0 comments
Open

hasOne or hasMany return null when $link with two bigint element #20124

easydowork opened this issue Mar 6, 2024 · 0 comments

Comments

@easydowork
Copy link

The model uses the hasOne method. If the link parameter is an array with two keys and the key is bigint, an error will occur. The reason is that the generated SQL will convert bigint into a string in PHP 7.4. The SQL is as follows:

#sql1
SELECT * From TABLE WHERE (` id1 `, ` id2 `) IN ('bigint ',' bigint ')

At this time, mysql8 cannot find data. At the end of the filterByModels method in the file db/ActiveRelationTrait.php, the andWhere method is called, as follows:

$this ->and Where (['in ', $attributes, $values]);

If the SQL generated by the andWhere method is of the following type, then there is no problem.

#sql2
SELECT * FROM  TABLE WHERE (`id1` IN ('bigint1') AND `id2`IN (''bigint2')

If using php8, querying bigint will return an integer, and using sql1 is not a problem,

If using PHP 8 or below, it is also possible to configure data connections when connecting to the database as follows:

'db' => [
     .....,
    'attributes' => [
          \PDO::ATTR_EMULATE_PREPARES => false,
    ]
]

But the bigint returned by JSON data will exceed the maximum number of JS, so I suggest that andWhere generate sql2. Is this suggestion feasible

Additional info

Q A
Yii version 2.0.49.2
PHP version PHP7.4
MYSQL version 8.0.35
Operating system centos7.9
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant