michaeldyrynda / laravel-model-uuid

This package allows you to easily work with UUIDs in your Laravel models
MIT License
442 stars 46 forks source link

Prepend column name with table name. #102

Closed robvankeilegom closed 3 years ago

robvankeilegom commented 3 years ago

This PR makes is possible to use whereUuid on relations where both models have a uuid field.

ex: A Project model with a Deployments hasManyThrough relation (from: https://laravel.com/docs/8.x/eloquent-relationships#has-many-through)

query:

$deployment = $project->deployments()
                  ->whereUuid($uuid)
                  ->dd();

before change:

select * from `deployments` 
inner join `environments` on `environments`.`id` = `deployments`.`environment_id` 
where `environments`.`project_id` = ? 
and `uuid` in (?) #difference
and `deployments`.`deleted_at` is null 
and `environments`.`deleted_at` is null

after change:

select * from `deployments` 
inner join `environments` on `environments`.`id` = `deployments`.`environment_id` 
where `environments`.`project_id` = ? 
and `deployments`.`uuid` in (?) #difference
and `deployments`.`deleted_at` is null 
and `environments`.`deleted_at` is null
michaeldyrynda commented 3 years ago

Thanks! I inlined the variable and added some tests for this.