fuel / docs

Fuel PHP Framework - Fuel v1.x documentation
http://fuelphp.com/docs
Other
166 stars 233 forks source link

added example of assigning permission to users #740

Closed Qchmqs closed 7 years ago

Qchmqs commented 7 years ago

it took me a while to figure out how to do this on my own

WanWizard commented 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.

WanWizard commented 7 years ago

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.

WanWizard commented 7 years ago

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.