Ad

How To Create 0..1 To Many Relationship In Octobercms?

- 1 answer

I have a table category it has a self relation to have belongs_to simply to be able to create subcategories and assign them to previously created categories and now i need to be able to either assign the new category to another (super) category or to assign it to none.

my model is :

    public $belongsTo = [
    'category' => ['plugin\pdf\models\Category']
];
Ad

Answer

This is found in the documents under backend -> forms. Look for the relation under widget fields. The option you is called emptyOption and it will be added in your fields.yaml file.

You would add the emptyOption like so to model's fields.yaml.

    field:
        label: Field Label
        nameFrom: name
        descriptionFrom: description
        span: auto
        type: relation
        emptyOption: None
Ad
source: stackoverflow.com
Ad