Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Add expressionToString to getOtherClauses #451

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

Merged
mikebronner merged 2 commits into mikebronner:master from padre:patch-1
Dec 23, 2023

Conversation

@padre
Copy link
Contributor

@padre padre commented May 11, 2023
edited
Loading

Fix exception: Object of class Illuminate\Database\Query\Expression could not be converted to string

Related: #441

Eloquent query that caused the bug, for example:


$this
 ->vigilances()
 ->has('investigations', '=', 1);

If i try to dump $where variable and got:

array:5 [▼ // vendor/genealabs/laravel-model-caching/src/CacheKey.php
 "type" => "Basic"
 "column" => Illuminate\Database\Query\Expression {#4958 ▼
 #value: "(select count(*) from `investigations` inner join `investigation_vigilance` on `investigations`.`id` = `investigation_vigilance`.`investigation_id` where `vigilances`.`id` = `investigation_vigilance`.`vigilance_id` and `investigations`.`deleted_at` is null) ◀"
 }
 "operator" => "="
 "value" => Illuminate\Database\Query\Expression {#4960 ▼
 #value: 1
 }
 "boolean" => "and"
]

Fix error: Object of class Illuminate\Database\Query\Expression could not be converted to string
Copy link
Contributor Author

padre commented Jun 30, 2023

@mikebronner can you merge this, please?

Thanks!

Copy link
Owner

mikebronner commented Jun 30, 2023
edited
Loading

@padre could you add a test that covers this specific use-case? I also made some small tweaks to the code.

Copy link
Contributor Author

padre commented Jul 4, 2023
edited
Loading

@mikebronner Thank you very much for your quick response and your attention, but I don't think I have the necessary knowledge to add a test.

The exception occurs when I use ->has() in a belongsToMany relationship.

class Investigation extends Model
{
 public function vigilances()
 {
 return $this->belongsToMany(Vigilance::class);
 }
}
class Vigilance extends Model
{
 public function investigations()
 {
 return $this->belongsToMany(Investigation::class);
 }
}
$investigation
->vigilances()
->has('investigations', '=', 1)
->get();

This causes in the method "getOtherClauses(array $where)" in the statement

$column .= isset($where["column"]) ? $where["column"] : "";

the exception "Object of class IlluminateDatabaseQueryExpression could not be converted to string".

If i try to dump $where variable and got:

array:5 [
 "type" => "Basic"
 "column" => Illuminate\Database\Query\Expression {#3051 ▼
 #value: "(select count(*) from `investigations` inner join `investigation_vigilance` on `investigations`.`id` = `investigation_vigilance`.`investigation_id` where `vigilances`.`id` = `investigation_vigilance`.`vigilance_id` and `investigations`.`deleted_at` is null) ◀"
 }
 "operator" => "="
 "value" => Illuminate\Database\Query\Expression {#3053 ▼
 #value: 1
 }
 "boolean" => "and"

Thank you very much for your dedication.

@mikebronner mikebronner merged commit 650e20d into mikebronner:master Dec 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

AltStyle によって変換されたページ (->オリジナル) /