Version: current

# Class ComponentSet

This is a special kind of DataObjectSet used to represent the items linked to in a 1-many or many-many join. It provides add and remove methods that will update the database.

  Object
  ViewableData implements IteratorAggregate
  DataObjectSet implements IteratorAggregate, Countable
  ComponentSet

### Direct known subclasses

`Member_GroupSet`

Package: sapphire\model
Located at sapphire/core/model/ComponentSet.php

## Methods summary

`public` | # `setComponentInfo( string $type, `DataObject` $ownerObj, string $ownerClass, string $tableName, string $childClass, string $joinField = null )` Set the ComponentSet specific information. Set the ComponentSet specific information. #### Parameters $type string $type Type of relationship (eg '1-1', '1-many'). $ownerObj DataObject $ownerObj Object that owns this set. $ownerClass string $ownerClass Class of object that owns this set. $tableName string $tableName Table that holds this relationship. $childClass string $childClass Class of child side of the relationship. $joinField string $joinField Field to join on.
`public array` | # `getComponentInfo( )` Get the ComponentSet specific information Get the ComponentSet specific information Returns an array on the format array( 'type' => <string>, 'ownerObj' => <Object>, 'ownerClass' => <string>, 'tableName' => <string>, 'childClass' => <string>, 'joinField' => <string>|null ); #### Returns `array` array
`public array` | # `getIdList( )` Get an array of all the IDs in this component set, where the keys are the same as the values. Get an array of all the IDs in this component set, where the keys are the same as the values. #### Returns `array` array
`public` | # `add( `DataObject`|integer|string $item, array $extraFields = null )` Add an item to this set. Add an item to this set. #### Parameters $item DataObject|int|string $item Item to add, either as a DataObject or as the ID. $extraFields array $extraFields A map of extra fields to add.
`protected` | # `loadChildIntoDatabase( `DataObject`|string|integer $item, array $extraFields = null )` Method to save many-many join data into the database for the given $item. Used by add() and write(). Method to save many-many join data into the database for the given $item. Used by add() and write(). #### Parameters $item DataObject|string|int The item to save, as either a DataObject or the ID. $extraFields array $extraFields Map of extra fields.
`public` | # `addMany( array $items )` Add a number of items to the component set. Add a number of items to the component set. #### Parameters $items array $items Items to add, as either DataObjects or IDs.
`public` | # `setByIDList( array $idList )` Sets the ComponentSet to be the given ID list. Records will be added and deleted as appropriate. Sets the ComponentSet to be the given ID list. Records will be added and deleted as appropriate. #### Parameters $idList array $idList List of IDs.
`public` | # `remove( `DataObject`|string|integer $item )` Remove an item from this set. Remove an item from this set. #### Parameters $item DataObject|string|int $item Item to remove, either as a DataObject or as the ID. #### Overrides `DataObjectSet::remove`
`public` | # `removeMany( array $itemList )` Remove many items from this set. Remove many items from this set. #### Parameters $itemList array $itemList The items to remove, as a numerical array with IDs or as a DataObjectSet
`public` | # `removeAll( )` Remove all items in this set. Remove all items in this set.
`public` | # `write( boolean $firstWrite = false )` Write this set to the database. Called by DataObject::write(). Write this set to the database. Called by DataObject::write(). #### Parameters $firstWrite boolean $firstWrite This should be set to true if it the first time the set is being written.
`public string` | # `debug( )` Returns information about this set in HTML format for debugging. Returns information about this set in HTML format for debugging. #### Returns `string` string #### Overrides `DataObjectSet::debug`

### Methods inherited from DataObjectSet

`Count()`, `CurrentPage()`, `First()`, `FirstItem()`, `GroupedBy()`, `Last()`, `LastItem()`, `MoreThanOnePage()`, `NextLink()`, `NotFirstPage()`, `NotLastPage()`, `Pages()`, `PaginationSummary()`, `PrevLink()`, `TotalItems()`, `TotalPages()`, `UL()`, `__construct()`, `addWithoutWrite()`, `buildNestedUL()`, `column()`, `containsIDs()`, `destroy()`, `emptyItems()`, `exists()`, `find()`, `forTemplate()`, `getChildrenAsUL()`, `getIterator()`, `getPageLimits()`, `getRange()`, `groupBy()`, `groupWithParents()`, `hasValue()`, `insertFirst()`, `map()`, `merge()`, `onlyContainsIDs()`, `parseQueryLimit()`, `pop()`, `push()`, `removeDuplicates()`, `replace()`, `setPageLength()`, `setPageLimits()`, `setPaginationGetVar()`, `shift()`, `sort()`, `toArray()`, `toDropDownMap()`, `toNestedArray()`, `unshift()`

### Methods inherited from ViewableData

`ATT_val()`, `BaseHref()`, `CSSClasses()`, `ColumnBreak()`, `ColumnCalc()`, `ColumnNumber()`, `ColumnPad()`, `ColumnPos()`, `CurrentMember()`, `Debug()`, `Even()`, `EvenOdd()`, `FirstLast()`, `HasPerm()`, `IsAjax()`, `JS_val()`, `Me()`, `Middle()`, `MiddleString()`, `Modulus()`, `MultipleOf()`, `Odd()`, `Pos()`, `RAW_val()`, `SQL_val()`, `ThemeDir()`, `ThemeName()`, `Top()`, `XML_val()`, `__get()`, `__isset()`, `__set()`, `buildCastingCache()`, `cachedCall()`, `castingClass()`, `castingHelper()`, `castingHelperPair()`, `castingObjectCreator()`, `castingObjectCreatorPair()`, `customise()`, `defineMethods()`, `escapeTypeForField()`, `getField()`, `getSecurityID()`, `getXMLValues()`, `hasField()`, `i18nLocale()`, `iteratorProperties()`, `obj()`, `renderWith()`, `setCustomisedObj()`, `setField()`

### Methods inherited from Object

`__call()`, `__toString()`, `__wakeup()`, `addMethodsFrom()`, `addStaticVars()`, `addWrapperMethod()`, `add_extension()`, `add_static_var()`, `allMethodNames()`, `cacheToFile()`, `cacheToFileWithArgs()`, `clearCache()`, `combined_static()`, `create()`, `createMethod()`, `create_from_string()`, `extInstance()`, `extend()`, `getCustomClass()`, `getExtensionInstance()`, `getExtensionInstances()`, `get_extensions()`, `get_static()`, `hasExtension()`, `hasMethod()`, `has_extension()`, `invokeWithExtensions()`, `is_a()`, `loadCache()`, `parentClass()`, `parse_class_spec()`, `remove_extension()`, `sanitiseCachename()`, `saveCache()`, `set_stat()`, `set_static()`, `set_uninherited()`, `stat()`, `strong_create()`, `uninherited()`, `uninherited_static()`, `useCustomClass()`

### Methods inherited from Countable

`count()`

### Magic methods summary

## Properties summary

`protected string` | $type | # Type of relationship (eg '1-1', '1-many'). Type of relationship (eg '1-1', '1-many').
`protected `DataObject`` | $ownerObj | # Object that owns this set. Object that owns this set.
`protected string` | $ownerClass | # Class of object that owns this set. Class of object that owns this set.
`protected string` | $tableName | # Table that holds this relationship. Table that holds this relationship.
`protected string` | $childClass | # Class of child side of the relationship. Class of child side of the relationship.
`protected string` | $joinField | # Field to join on. Field to join on.

### Properties inherited from DataObjectSet

`$current`, `$first`, `$items`, `$last`, `$odd`, `$pageLength`, `$pageStart`, `$paginationGetVar`, `$totalSize`

### Properties inherited from ViewableData

`$casting`, `$customisedObject`, `$default_cast`, `$failover`, `$iteratorPos`, `$iteratorTotalItems`

### Properties inherited from Object

`$class`, `$extension_instances`, `$extensions`

[Raise a SilverStripe Framework issue/bug](https://github.com/silverstripe/silverstripe-framework/issues/new)
- [Raise a SilverStripe CMS issue/bug](https://github.com/silverstripe/silverstripe-cms/issues/new)
- Please use the Silverstripe Forums to ask development related questions. -