{"action":"opened","issue":{"url":"https://api.github.com/repos/laravel/framework/issues/25209","repository_url":"https://api.github.com/repos/laravel/framework","labels_url":"https://api.github.com/repos/laravel/framework/issues/25209/labels{/name}","comments_url":"https://api.github.com/repos/laravel/framework/issues/25209/comments","events_url":"https://api.github.com/repos/laravel/framework/issues/25209/events","html_url":"https://github.com/laravel/framework/issues/25209","id":350418894,"node_id":"MDU6SXNzdWUzNTA0MTg4OTQ=","number":25209,"title":"The BelongsToMany relation doesn't attach/detach relations when used custom fields instead a PK.","user":{"login":"dkulyk","id":370042,"node_id":"MDQ6VXNlcjM3MDA0Mg==","avatar_url":"https://avatars3.githubusercontent.com/u/370042?v=4","gravatar_id":"","url":"https://api.github.com/users/dkulyk","html_url":"https://github.com/dkulyk","followers_url":"https://api.github.com/users/dkulyk/followers","following_url":"https://api.github.com/users/dkulyk/following{/other_user}","gists_url":"https://api.github.com/users/dkulyk/gists{/gist_id}","starred_url":"https://api.github.com/users/dkulyk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dkulyk/subscriptions","organizations_url":"https://api.github.com/users/dkulyk/orgs","repos_url":"https://api.github.com/users/dkulyk/repos","events_url":"https://api.github.com/users/dkulyk/events{/privacy}","received_events_url":"https://api.github.com/users/dkulyk/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-08-14T13:03:54Z","updated_at":"2018-08-14T13:03:54Z","closed_at":null,"author_association":"NONE","body":"- Laravel Version: 5.5+\r\n- PHP Version: 7.2\r\n- Database Driver & Version: MariaDB 10.2\r\n\r\n### Description:\r\n\r\nWhen used custom parentKey and/or relatedKey in the BelongsToMany relation the relation use PK instead custom key names: ([InteractsWithPivotTable::parseIds()](https://github.com/laravel/framework/blob/5.6/src/Illuminate/Database/Eloquent/Relations/Concerns/InteractsWithPivotTable.php#L474))\r\n\r\n### Steps To Reproduce:\r\n\r\n`use Illuminate\\Database\\Eloquent\\Model;\r\nuse Illuminate\\Database\\Eloquent\\Relations\\BelongsToMany;\r\n\r\n/**\r\n * Class User\r\n * @package App\\Models\r\n * @property-read int $id\r\n */\r\nclass User extends Model\r\n{\r\n    protected $table = 'users';\r\n\r\n    public function roles(): BelongsToMany\r\n    {\r\n        return $this->belongsToMany(Role::class, 'user_roles', 'user_id', 'role', 'id', 'identifier')\r\n    }\r\n}\r\n\r\n/**\r\n * Class Role\r\n * @package App\\Models\r\n * @property-read int    $id\r\n * @property-read string $identifier\r\n */\r\nclass Role extends Model\r\n{\r\n    protected $table = 'roles';\r\n}\r\n\r\n\r\n$user = User::query()->find(1);\r\n$role = Role::query()->where('identifier','=','admin')->first();\r\n\r\n$user->roles()->attach($role);`"}}
{"actor":{"display_login":"dkulyk"}}