mpociot / teamwork

User to Team associations with invitation system for the Laravel 5 Framework
MIT License
1.07k stars 170 forks source link

Append table name to Builder to prevent conflicting `ID`s in SQL query #139

Open kyranb opened 3 years ago

kyranb commented 3 years ago

Fixes the issue "Column 'id' in where clause is ambiguous" when using additional scopes.

Example query that fails due to not specifying the table name for id:

SQLSTATE[23000]: Integrity constraint violation: 1052 Column 'id' in where clause is ambiguous (SQL: select users.*, tenants_user.team_id as pivot_team_id, tenants_user.user_id as pivot_user_id, tenants_user.created_at as pivot_created_at, tenants_user.updated_at as pivot_updated_at from users inner join tenants_user on users.id = tenants_user.user_id where tenants_user.team_id = 2 and id = 1 and users.deleted_at is null limit 1)

kyranb commented 3 years ago

@mpociot

rodriguezaitor commented 2 years ago

Same issue here..

kyranb commented 2 years ago

@mpociot Can this be merged in? I've been using the fork without issue in production for almost 1 year now :)

okaufmann commented 2 years ago

@kyranb when the tests are green, we will consider merging it.

kyranb commented 2 years ago

@okaufmann Can you take a look? I'm not that familiar with mockery, but it looks like just the table name (users) needs to be added in somewhere as the query now includes that.

okaufmann commented 1 year ago

@kyranb please merge the current master in your feature branch so the latest test actions can run again.

kyranb commented 1 year ago

@okaufmann Sorry for the delay here Oliver. I've just done so :)

kyranb commented 1 year ago

@okaufmann @mpociot Can this be reviewed or merged?

kyranb commented 11 months ago

@mpociot @okaufmann Bump :)