Open johnwilhite opened 6 years ago
Hi John. Sorry for the late response.
Could you supply the db schema and the full model code that you are using?
This is how I just managed to solve it, I think. Haven't tested it thoroughly. Makes sense?
public function fillBelongsToRelation(BelongsTo $relation, $attributes, $relationName)
{
$entity = $attributes;
$created = self::getModelName($relationName)::create($entity);
$relation->associate($created);
// if (!$attributes instanceof Model) {
// $entity = $relation->getRelated()
// ->where($attributes)->firstOrFail();
// }
// $relation->associate($entity);
}
private static function getModelName($name)
{
return 'App\Models\' . rtrim(ucfirst($name), 's');
}
This is a similar issue to https://github.com/troelskn/laravel-fillable-relations/issues/5.
The trait is failing on the following example:
The
fillBelongsToRelation
save for customer fails with the following, because it's trying to selectreference
, which is the relation and not a column, from thecustomers
table.The following seems to fix the issue for belongsTo relations, it's extracting the relations out and only using the attributes in that lookup.
Would this be an appropriate fix? Also I haven't tested the belongs to many, but I'd imagine it would need a similar fix.