SilverStripe 3 GridField based management of has_one , has_many , and many_many relationship selection
- SilverStripe >= 3.1
- Andrew Short's GridFieldExtensions [ https://github.com/ajshort/silverstripe-gridfieldextensions ]
- Because I needed a consistent interface to manage relationship selections in an efficient* manner.
- GridField doesn't appear to natively support has_one relationships.
Thanks to the great work of the SilverStripe team and Andrew Short's GridFieldExtensions, this was relatively easy to implement. Please by them beers or tea.
* by efficient we needed ajax + pagination, as we couldn't load all records into a dropdown list for instance.
Screenshots;
- overview - https://github.com/briceburg/silverstripe-pickerfield/blob/master/docs/screenshots/pickerfield.png
- link button search [via GridFieldExtensions] - https://github.com/briceburg/silverstripe-pickerfield/blob/master/docs/screenshots/add-existing-search.png
/***********************
Mock DataObject
************************/
class Dog extends DataObject {
static $db = array(
'Title' => 'Varchar',
// ....
);
static $has_one = array(
'Breeder' => 'Breeder'
// ....
);
static $has_many = array(
'Owners' => 'Member',
// ....
);
// ....
}
/***********************
Field Usage
************************/
// sortable field appropriate for selection of has_many and many_many objects
$field = new PickerGridField('Owners', 'Owners', $this->Owners(), 'Select Owner(s)', 'SortOrder');
// non-sortable version of the above
$field = new PickerGridField('Owners', 'Owners', $this->Owners());
// sortable field appropriate for the parent selection of a has_one relationship
new HasOnePickerGridField($this, 'BreederID','Breeder', 'Breeder', 'Select a Breeder')
For support or questions, please use the GitHub provided issue tracker;