If I dump the sql for the query using toSql(), I get this:
select * from `permissions` inner join `vendor_permissions` on `permissions`.`id` = `vendor_permissions`.`permission_id` where `vendor_permissions`.`vendor_id` = ?
But the ACTUAL query that is being sent to my database, is this:
select `permissions`.*, `vendor_permissions`.`vendor_id` as `pivot_vendor_id`, `vendor_permissions`.`permission_id` as `pivot_permission_id` from `permissions` inner join `vendor_permissions` on `permissions`.`id` = `vendor_permissions`.`permission_id` where `vendor_permissions`.`vendor_id` = ?
as you can see, they are quite a bit different. Why is this? I am trying to clear the query cache for a relation, and to do that I need to be able to get the actual query being used, so how do I do that?
To reconstruct the query that is actually being run, you need to add to the select the pivot columns. This function does it:
So to clear the cache for the relation attribute, you can do this: