You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have a Project that hasMany Contracts while a Contract belongsTo a project. Contracts can be of many types.
Contract also has a morphMany relation to Document and uses protected $withCount="['documents']
The problem manifests when I try to query Projects that have Contracts of a certain type. In this case nothing is returned because of incorrect bindings.
Steps To Reproduce:
I'm using tinker with DB::enableQueryLog() / DB::getQueryLog()
The following query:
Project::whereHas('contracts')->get()
returns the collection of projects that have at least one contract, even if the query log shows an extra binding:
[
"query" => "select * from `projects` where exists (select * from `contracts` where `projects`.`id` = `contracts`.`project_id`)",
"bindings" => [
"App\Contract", //notice this
],
"time" => 1.39,
],
#25997 will probably make possible at least a workaround
The text was updated successfully, but these errors were encountered:
aocneanu
changed the title
Wrong bindings when calling whereHas on a relation that uses $withCount
[5.7]Wrong bindings when calling whereHas on a relation that uses $withCountOct 16, 2018
aocneanu
changed the title
[5.7]Wrong bindings when calling whereHas on a relation that uses $withCount
[5.7] Wrong bindings when calling whereHas on a relation that uses $withCountOct 16, 2018
Description:
I have a Project that
hasMany
Contracts while a ContractbelongsTo
a project. Contracts can be of many types.Contract also has a
morphMany
relation to Document and usesprotected $withCount="['documents']
The problem manifests when I try to query Projects that have Contracts of a certain type. In this case nothing is returned because of incorrect bindings.
Steps To Reproduce:
I'm using
tinker
withDB::enableQueryLog()
/DB::getQueryLog()
The following query:
returns the collection of projects that have at least one contract, even if the query log shows an extra binding:
While this query:
returns an empty collection and the query log is:
The query as shown by the DebugBar:
I found many previous issues and PRs related to this problem but apparently the above scenario is still not covered:
ref #24240, #24865, #25280, #24240
#25997 will probably make possible at least a workaround
The text was updated successfully, but these errors were encountered: