Hi Guys! I have a some problem with saving existed models as manytomany relations. If i create new, all fine.
$groups = [];
$groups[0] = new UserGroups;
$groups[0]->name = 'test2';
$groups[0]->active = 1;
$user = new static;
$user->assign($data);
$user->groups = $groups;
$user->create();
but if i set existed
$groups = UserGroups::find([1])->toArray();
$user = new static;
$user->assign($data);
$user->groups = $groups;
$user->create();
I get error
Record cannot be created because it already exists
If i change create to save, user with id=1 is updated.
If set groups as ResultSet
, nothing added in relations table, but new user is created
$groups = UserGroups::find([1]);
$user = new static;
$user->assign($data);
$user->groups = $groups;
$user->create();