laravel-bakery
laravel-bakery copied to clipboard
Pivot fields missing for uni-directional relation
Describe the bug
When a relation is only specified in one direction on the ModelSchema, then the pivot fields are on the wrong side of the relation. For example, when there is a relationship users
belongs to many roles
, there is a rolesPivot
on the User
type. While there should only be a usersPivot
on the Roles
type, because there is no way to retrieve the users from the roles.
To Reproduce
// UserSchema.php
public function relations(): array
{
return [
'roles' => Field::collection(RoleSchema::class),
];
}
// RoleSchema.php
public function relations(): array
{
return [];
}
// UserRole.php
public function fields(): array
{
return [
'comment' => Field::string(),
];
}
{
user(id: 1) {
roles {
userPivot { comment }
}
}
}
# "{"errors":[{"message":"Cannot query field \"userPivot\" on type \"Role\".","category":"graphql","locations":[{"line":3,"column":17}]}]}"
- Laravel Version: v5.7.27
- Bakery Version v3.0.0