This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.

billyZduke
billyZduke

If your relationship is many-to-many, then you can just leave all the boxes unchecked, but if it's a one-to-many that produces a dropdown field, you've currently got to do some acrobatics (unless I'm missing something?) to be able to allow the user to save the model without a parent_id value being automatically shoehorned in.

You can see a perfect example of one attempt around this in Feegleweb\Octoshop\Models\Category, where he creates a purgeable switch field ("Is this a sub-category?") to toggle the display of the relation dropdown, and then discards the value in the controller if one gets submitted when the switch is set to off...

alexc
alexc

You can use the emptyOption param to achieve this:

# ===================================
#  Form Field Definitions
# ===================================

fields:
    id:
        label: ID
        disabled: true
    name:
        label: Name
        required: true
    parent:
        label: Parent
        type: relation
        nameFrom: name
        emptyOption: None

1-2 of 2

You cannot edit posts or make replies: the forum has moved to talk.octobercms.com.