-
Notifications
You must be signed in to change notification settings - Fork 125
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
GridFieldEditableColumns does not work with ManyManyThroughList #309
Comments
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`.
I just opened a PR that allows me to use the first approach, i.e.: $config->getComponent>ByType(GridFieldEditableColumns::class)->setDisplayFields([
'SomeData' => 'A really useful field',
]); |
The recently merged #294, together with silverstripe/silverstripe-framework#9192, will allow to properly use dot syntax in this cases, e.g. the following code should work: $config->getComponent>ByType(GridFieldEditableColumns::class)->setDisplayFields([
'TeamSupporter.SomeData' => 'A really useful field',
]); Although not released, one can leverage {
...
"require": {
...
"cweagans/composer-patches": "^1.0"
},
"extra": {
"patches": {
"silverstripe/framework": {
"Support dot syntax in ManyManyThroughList": "https://github.com/silverstripe/silverstripe-framework/pull/9192.patch"
}
}
}
} |
silverstripe/silverstripe-framework#9192 has been recently merged, so I consider this issue solved. |
I just tried to substitute the two occurrences of
$list instanceof ManyManyList
with($list instanceof ManyManyList || $list instanceof ManyManyThroughList)
but it does not seem to work properly.Let's pretend to have the following data model:
With the following code in
Team::getCMSFields
(that works properly whenSomeData
is defined as$many_many_extraFields
), I am able to change it (I see the new value in the database) but the form field element is not properly populated (it is always empty):With the following code, the form field is properly populated but it is turned readonly:
Unfortunately I need to use an explicit through relation to be able to
populateDefaults()
the extra fields and add some calculated field. If anyone has a better idea I'm all ears.The text was updated successfully, but these errors were encountered: