You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/php/database-objects.md
+95Lines changed: 95 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -169,6 +169,101 @@ Of course, you do not have to set the property after creating the list object, y
169
169
) }}
170
170
171
171
172
+
## DatabaseObjectCollection
173
+
174
+
A Database Object Collection is a container for a group of `DatabaseObject` instances that optimizes how additional runtime data is loaded and shared between objects.
175
+
176
+
### Motivation
177
+
178
+
Some database objects require extra runtime data (e.g., a UserProfile or file attachments).
179
+
Loading this data on demand per object is inefficient, as it requires repeated queries for each object.
180
+
181
+
Earlier approaches (e.g., the Viewable* classes) tried to address this by preloading extra data:
182
+
183
+
- ✅ Efficient in some cases, especially when JOINs are used.
184
+
- ❌ Can be wasteful if not all of the extra data is needed.
185
+
- ❌ JOIN-based solutions lack reliable type hints, sometimes resulting in missing or inconsistent data.
When instantiating the collection, `CollectionDatabaseObject` searches by default for a class that matches the class name of the database object and contains the suffix `Collection.`
220
+
However, by overwriting the `getCollectionClassName()` method, you can also use a custom class name.
221
+
222
+
```php
223
+
class FooObjectCollection extends DatabaseObjectCollection {
224
+
private bool $userProfilesLoaded = false;
225
+
226
+
public function getUserProfile(FooObject $object): UserProfile
0 commit comments