Save $many_many_extraFields when adding a DataObject to a list

Assuming you have a $many_many relation and SortOrder defined as $many_many_extraFields you can add an item to this ManyManyList and pass the extraFields as an array:

private static $many_many = ['Images' => 'Image];

private static $many_many_extraFields = [
    'Images' => ['SortOrder' => 'Int']
];

public function doSomething() {
    //do something

    $image = Image::create();

    //save image and stuff

    //...

    //add to many_many relation

    $this->Images()->add($image, ['SortOrder' => $currentSort]);

    //...
}
Rate this post

Post your comment

Comments

No one has commented on this page yet.

RSS feed for comments on this page | RSS feed for all comments