October CMS resources and help articles

Simple and to the point. Optimized by the community.

Default for Many to Many Relationship Using the Relation Controller

0
by minakari, last modified on February 13th, 2024

When using a many to many relation using the relation controller you can set a default value like so—illustrated using a many to many relation ship to users:

Controller

    public function formExtendFields($form)
    {
        if ($this->formGetContext() === 'create') {
            $model = $this->formCreateModelObject();
            $sessionKey = $this->formGetSessionKey()`
            $currentUser = BackendAuth::getUser();

            $model->users()->add($currentUser, $sessionKey);
        }
    }

Discussion

0 comments

We use cookies to measure the performance of this website. Do you want to accept these cookies?