-
Notifications
You must be signed in to change notification settings - Fork 94
Fix table name usage in clauses #56
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
Fix table name usage in clauses #56
Conversation
|
By using the function setApplyColumnCheck, it then bypass the checking on column and apply original where clause. $query = Entry::query()
->setApplyColumnCheck(false) |
|
Would a better fix not be to change the |
This line was not introduced by me. |
|
You are misunderstanding... you could do the same effect of what your changes have done by simpyl checking if |
Do you mean like this? protected function column($column)
{
if (! is_string($column)) {
return $column;
}
if ($column == 'origin') {
$column = 'origin_id';
}
if (in_array($column, self::COLUMNS)) {
if (! Str::contains($column, 'data->')) {
$column = 'data->'.$column;
}
}
return $column;
} |
|
Yep - basically... one small change (maybe a copy/paste issue on your side). does that change fix your issue? |
It looks you are right. Let me check it up. Thanks |
This would generate the following SQL in which the location part is incorrect. select * from "entries"
inner join "entries" as "e" on "e"."id" = "entries"."id" and "e"."collection" = ?
left join "entries" as "locations" on "locations"."collection" = ? and "locations"."id" = json_extract("e"."data", '$."location"')
where json_extract("e"."data", '$."title"') like ? and json_extract("data", '$."locations.slug"') = ? |
|
What about adding a check for the table alias... something like: |
Thanks a lot. You logic is right. Do you think this is simplier? protected function column($column)
{
if (! is_string($column)) {
return $column;
}
if ($column == 'origin') {
$column = 'origin_id';
}
if (! in_array($column, self::COLUMNS)) {
if (! Str::contains($column, 'data->')) {
if (! Str::contains($column, '.') ) {
$column = 'data->'.$column;
}
}
}
return $column;
} |
|
Simpler yes but it wouldn’t work the same. Stick with what I did :)
… On 5 Sep 2022, at 14:49, maxwkf ***@***.***> wrote:
What about adding a check for the table alias... something like:
protected function column($column)
{
if (! is_string($column)) {
return $column;
}
$table = Str::contains($column, '.') ? Str::before($column, '.') : '';
$column = Str::after($column, '.');
if ($column == 'origin') {
$column = 'origin_id';
}
if (! in_array($column, self::COLUMNS)) {
if (! Str::contains($column, 'data->')) {
$column = 'data->'.$column;
}
}
return ($table ? $table.'.' : '').$column;
}
Thanks a lot. You logic is right. Do you think this is simplier?
protected function column($column)
{
if (! is_string($column)) {
return $column;
}
if ($column == 'origin') {
$column = 'origin_id';
}
if (! in_array($column, self::COLUMNS)) {
if (! Str::contains($column, 'data->')) {
if (! Str::contains($column, '.') ) {
$column = 'data->'.$column;
}
}
}
return $column;
}
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you commented.
|
Hi Ryan, Thanks for your help. Updated according to our discussion. Do I need to close the pull request or leave it as open? |
|
Leave it open :) |
|
Fixes #55