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

mihai8287
mihai8287

I have two models in a belongsToMany relation. I have set up a backend form with a repeater widget that allows attaching a number of related models using values from the pivot table. I got it to save the data into the pivot table, but that data is never displayed on the form. Even the number of rows in the repeater widget are correct, but apparently the values never make it to the form fields (they are always null).

Here is my setup:

relation_config.yaml

knowledge:
    label: Knowledge
    pivot:
        form:
            fields:
                knowledge_id:
                    label: Field
                score:
                    label: Score

fields.yaml

fields:
    title:
        label: Academic program title

    knowledge:
        type: repeater
        form:
            fields:
                knowledge_id:
                    label: Field
                score:
                    label: Score

in Models\Program.php i have

public $belongsToMany = [
    'knowledge' => [
        'Blah\Mockup\Models\Knowledge',
        'table' => 'blah_knowledge_program',
        'primaryKey' => 'program_id',
        'foreignKey' => 'knowledge_id',
        'pivot' => ['score']
    ]
];

Am I doing something wrong?

Last updated

akhil.mokariya63673
akhil.mokariya63673

@mihai8287 Did you get the answer? Because the same things happened to me.

mjauvin
mjauvin

You're treating your knowledge field with type repeater as a relation, which it is not.

1-3 of 3

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