laravel / framework

The Laravel Framework.
https://laravel.com
MIT License
32.64k stars 11.04k forks source link

fix: use qualifyColumn rather than assuming format #53559

Closed willtj closed 3 days ago

willtj commented 3 days ago

In my setup I have some Laravel models stored in MongoDB and others in MySQL. MorphTo and BelongsTo relations aren't loading where the parent model is in MongoDB and the child is in MySQL, i.e:

class Parent extends MongoModel
{

}

class Child extends EloquentModel
{
    public function myRelation()
    {
        return $this->belongsTo(Parent::class);
    }
}

Child::first()->myRelation will return null because addConstraints() is assuming that the key name should be prepended with the table name, which isn't the case for MongoDB.

The getQualifiedOwnerKeyName() method already exists on the BelongsTo class, is there any reason why it's not currently being used when adding constraints?

crynobone commented 3 days ago

This PR broken morphTo() usage. If for example we explicitly add qualifyColumn(string $column) multiple tests will be broken indicating an issue.

crynobone commented 3 days ago

This PR has been reverted due as it triggers error on certain MorphTo relationships. See https://github.com/laravel/framework/pull/53568