framework
framework copied to clipboard
[4.2] [Proposal] Make the belongsTo behavior more like the hasOne behavior
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();
Perhaps send a pull to 5.0 so we can exactly what you mean.