Skip to content

Commit

Permalink
FIX symbiote#309 Support ManyManyThroughList in EditableColumns
Browse files Browse the repository at this point in the history
The ManyManyThrough fields must be specified without comma, hence its
name must be unique in the joined set of fields. For example, given the
following DataObjects:
```
class Team extends DataObject
{
    private static $many_many = [
        "Supporters" => [
            'through' => TeamSupporter::class,
            'from' => 'Team',
            'to' => 'Supporter',
        ]
    ];
}
class Supporter extends DataObject
{
    private static $belongs_many_many = [
        'Supports' => Team::class,
    ];
}
class TeamSupporter extends DataObject
{
    private static $db = [
        'Ranking' => 'Int',
    ];
    private static $has_one = [
        'Team' => Team::class,
        'Supporter' => Supporter::class,
    ];
}
```
you should refer to the ranking field with `Ranking`, not with
`TeamSupporter.Ranking`.
  • Loading branch information
ntd committed Jun 10, 2020
1 parent 306ad52 commit 29079cd
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/GridFieldEditableColumns.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
use SilverStripe\ORM\DataObjectInterface;
use SilverStripe\ORM\FieldType\DBField;
use SilverStripe\ORM\ManyManyList;
use SilverStripe\ORM\ManyManyThroughList;

/**
* Allows inline editing of grid field records without having to load a separate
Expand Down Expand Up @@ -81,7 +82,14 @@ public function getColumnContent($grid, $record, $col)
}
$field = clone $field;
} else {
$value = $grid->getDataFieldValue($record, $col);
$value = $grid->getDataFieldValue($record, $col);
if (is_null($value)) {
// Try to find the value into the join record
$join = $record->getJoin();
if ($join) {
$value = $grid->getDataFieldValue($join, $col);
}
}
$rel = (strpos($col, '.') === false); // field references a relation value
$field = ($rel) ? clone $fields->fieldByName($col) : new ReadonlyField($col);

Expand Down Expand Up @@ -150,7 +158,7 @@ public function handleSave(GridField $grid, DataObjectInterface $record)
}
}

if ($list instanceof ManyManyList) {
if ($list instanceof ManyManyList || $list instanceof ManyManyThroughList) {
$extra = array_intersect_key($form->getData(), (array) $list->getExtraFields());
}

Expand Down Expand Up @@ -235,7 +243,7 @@ public function getFields(GridField $grid, DataObjectInterface $record)
}
}

if (!$field && $list instanceof ManyManyList) {
if (!$field && ($list instanceof ManyManyList || $list instanceof ManyManyThroughList)) {
$extra = $list->getExtraFields();

if ($extra && array_key_exists($col, $extra)) {
Expand Down

0 comments on commit 29079cd

Please sign in to comment.