Closed tostercx closed 6 years ago
Unrelated to this issue but in the same function - I think HasOne
relations usually work in the opposite direction?
As in the foreign table has a key that links back to this table.
https://laravel.com/docs/5.6/eloquent-relationships#one-to-one
Got it running for me with some dirty hacks :)
public function fillHasOneRelation(HasOne $relation, $attributes, $relationName)
{
$this->fillHasManyRelation($relation, [$attributes], $relationName);
}
// removed HasMany type
public function fillHasManyRelation($relation, array $attributes, $relationName)
{
...
}
You might consider merging HasOne
/ HasMany
in some (more elegant) way. It's basically the same kind of relation.
edit
Less hacky - type checking on 2 public methods, then proxying to a private non-typed.
Hey @tostercx thanks for your detective work. I hope to have time to look at this in a not too far future, but not sure when.
https://github.com/troelskn/laravel-fillable-relations/blob/1ef111fb7292098feb79108b77a8e630678a7760/src/Eloquent/Concerns/HasFillableRelations.php#L127
Seems Laravel renamed this method to
getQualifiedForeignKeyName
in 5.4?https://github.com/laravel/framework/blob/5.3/src/Illuminate/Database/Eloquent/Relations/HasOneOrMany.php#L378
https://github.com/laravel/framework/blob/5.4/src/Illuminate/Database/Eloquent/Relations/HasOneOrMany.php#L413
There's also a
getForeignKeyName
now, not sure what's the difference between the two.edit
I guess
getForeignKeyName
takes the part after the last dot, so there's no need to dostr_after
now.edit
Just noticed there's already a similar fix for
HasMany
relations, this bug is just forHasOne
.https://github.com/troelskn/laravel-fillable-relations/blob/1ef111fb7292098feb79108b77a8e630678a7760/src/Eloquent/Concerns/HasFillableRelations.php#L148-L153