mardi 31 mars 2020

mergeBindings returns result from one match only

I am using mergeBindings to perform a subquery on Eloquent, but the result of the query is that is just give me result for one matching row. Hence all the rows shows the same value even if the ID in the where condition is specified.

$sub = Permissions::select('name');
...
->mergeBindings($sub->getQuery()->where("user_id",'=','rhc.id'))

Permissions holds information about user permissions (name and id). In the query I list all the permission ID`s for a specific user (SELECT rhc.id). But the result always gives me the same permission name no matter what the permission ID is. Example result:

user id: 1
permissions_id :1
name: "Admin"

user id: 1
permissions_id :2
name: "Admin"

user id: 1
permissions_id :3
name: "Admin"

I expect name to be NULL since they are not specified yet (ID 1 is "Admin", which is therefore correct).

Can this be done or does the subquery only take the result from the first match in the subquery and not for each row?

Thanks for any help!



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2xBeBMZ
via IFTTT

Aucun commentaire:

Enregistrer un commentaire