File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 274274 });
275275});
276276
277+ test ('updating pivot column does not re-create the synced tenant resource ' , function () {
278+ // Add an extra pivot column so we can update it
279+ Schema::table ('tenant_users ' , fn (Blueprint $ table ) => $ table ->string ('note ' )->nullable ());
280+
281+ $ centralUser = CentralUser::create ([
282+ 'global_id ' => 'acme ' ,
283+ 'name ' => 'John Doe ' ,
284+ 'email ' => 'john@localhost ' ,
285+ 'password ' => 'secret ' ,
286+ 'role ' => 'commenter ' ,
287+ ]);
288+
289+ $ tenant = Tenant::create ();
290+ migrateUsersTableForTenants ();
291+
292+ // Attaching creates the tenant resource
293+ $ centralUser ->tenants ()->attach ($ tenant );
294+ $ tenant ->run (fn () => expect (TenantUser::count ())->toBe (1 ));
295+
296+ // Updating a pivot column does not re-attach and create the resource again
297+ // (which would throw a duplicate entry error -- regression test for #1467)
298+ $ centralUser ->tenants ()->updateExistingPivot ($ tenant ->getTenantKey (), ['note ' => 'foo ' ]);
299+
300+ $ tenant ->run (fn () => expect (TenantUser::count ())->toBe (1 ));
301+ });
302+
277303test ('detaching central users from tenants or vice versa force deletes the synced tenant resource ' , function (bool $ attachUserToTenant ) {
278304 $ centralUser = CentralUser::create ([
279305 'global_id ' => 'acme ' ,
You can’t perform that action at this time.
0 commit comments