Closed Qchmqs closed 7 years ago
That example might work, but it is only needed if you have per-permission actions (which the example doesn't use).
You could replace the entire $user_perm bit by
$user->permissions[] = $perm;
$user->save();
There is a standard many-many relation between user and permission.
unset() doesn't work with PHP 7.1?
Would you might having a look at __unset()
in the \Orm\Model
class, and see what happens if you use unset ($user->permissions)
?
The only difference I can find is that with unset
, $this->_reset_relations[$property]
is set to true, which doesn't happen if you assign NULL
to it and the relation is already fetched. This might indeed be a bug.
I checked the code under 7.0.
$model->relation = null;
and unset($model->relation);
generates exactly the same queries here (can be verified with the profiler).
Also tested with and without pre-fetching the related records, but that didn't make any difference.
it took me a while to figure out how to do this on my own