framework icon indicating copy to clipboard operation
framework copied to clipboard

[4.2] [Proposal] Make the belongsTo behavior more like the hasOne behavior

Open rickshawhobo opened this issue 12 years ago • 1 comments

Right now if you do

public function foo() {
return $this->belongsTo('User');
}

Laravel will look for the foreign key "foo_id". It should be looking for "user_id" It is a simple refactor that should maintain backward compatibility.

    if (is_null($foreignKey))
        {
            $foreignKey = snake_case($relation).'_id';
        }
        $instance = new $related;

Should become

        $instance = new $related;

        $foreignKey = $foreignKey ?: $instance->getForeignKey();

rickshawhobo avatar Nov 07 '14 22:11 rickshawhobo

Perhaps send a pull to 5.0 so we can exactly what you mean.

GrahamCampbell avatar Dec 27 '14 15:12 GrahamCampbell