MiretteMaged
MiretteMaged

Reputation: 15

How to create 0..1 to many relationship in octobercms?

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']
];

Upvotes: 0

Views: 51

Answers (1)

Pettis Brandon
Pettis Brandon

Reputation: 865

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

Upvotes: 2

Related Questions