Closed ebebbington closed 1 year ago
Hey there,
Can you first please try one of the support channels below? If you can actually identify this as a bug, feel free to open up a new issue with a link to the original one and we'll gladly help you out.
Thanks!
Laravel Version
10.0
PHP Version
8.2.7
Database Driver & Version
MYSQL 8.0.31 for Linux AMD64
Description
There seems to be an issue with
->getQuery()
when used on a belongs to many relationship, where the SQL itself and result set actually returns incorrect data. For example take say I have->belongsToMany(User:class)
, calling->getQuery()->get()
returns a collection ofUser
models, but theid
is that of the pivot, alongside the fields being a complete mix of both the pivot table and users tableSteps To Reproduce
organisations
. Assume this table has aorganisation_name
fieldusers
. Assume this table has ausername
fieldorganisation_user
, which has a foreign key fororganisation_id
anduser_id
organisations
table):users
table)(It's key that the id in all tables are different)
organisation_user
table)You will notice that the
id
of each model is actually the id of the pivot, and not from the users table, it then combines the fields so it may look like:As you can see, the model is
User
, but the id is from a different table, and contains fields from both theusers
and pivot table