ModelLinksSimpleArray
Class: ModelLinksSimpleArray<T>
Defined in: packages/models/src/relations.ts:507
Link to a collection of objects
Uses composition instead of extending Array for better maintainability, performance, and type safety.
This allows to do a n:m or 1:n relation between two models
It does not require to have a symetric relation on the other side The array contains uuid of the linked objects
Type Parameters
T
T extends Storable
Implements
Indexable
[
index:number]:ModelRef<T>
Support indexed access like an array
Constructors
Constructor
new ModelLinksSimpleArray<
T>(model,content?,parentObject?):ModelLinksSimpleArray<T>
Defined in: packages/models/src/relations.ts:520
Create a new ModelLinksSimpleArray
Parameters
model
ModelClass<T>
the model class for linked items
content?
PrimaryKeyType<T>[] = []
initial array of primary keys
parentObject?
T
optional parent object owning this relation
Returns
ModelLinksSimpleArray<T>
Properties
[RelationAttributes]
[RelationAttributes]:
object
Defined in: packages/models/src/relations.ts:509
[RelationRepository]
protected[RelationRepository]:Repository<ModelClass<T>>
Defined in: packages/models/src/relations.ts:510
[RelationRole]
[RelationRole]:
"Links"
Defined in: packages/models/src/relations.ts:508
Implementation of
Accessors
length
Get Signature
get length():
number
Defined in: packages/models/src/relations.ts:652
Get the number of items
Returns
number
the item count
Methods
[iterator]()
[iterator]():
Iterator<ModelRef<T>>
Defined in: packages/models/src/relations.ts:739
Make the collection iterable (for...of loops)
Returns
Iterator<ModelRef<T>>
an iterator over the items
add()
add(
model):void
Defined in: packages/models/src/relations.ts:618
Add a model to the collection
Parameters
model
string | T | PrimaryKeyType<T> | ModelRef<T>
the model to add
Returns
void
Deprecated
use push instead
at()
at(
index):ModelRef<T> |undefined
Defined in: packages/models/src/relations.ts:661
Get item at index
Parameters
index
number
the array index
Returns
ModelRef<T> | undefined
the item, or undefined
every()
every(
predicate):boolean
Defined in: packages/models/src/relations.ts:723
Check if all items match predicate
Parameters
predicate
(item, index, array) => boolean
the test predicate
Returns
boolean
true if all items match
filter()
filter(
predicate):ModelRef<T>[]
Defined in: packages/models/src/relations.ts:697
Filter items (does NOT mutate)
Parameters
predicate
(item, index, array) => boolean
the filter predicate
Returns
ModelRef<T>[]
the filtered items
find()
find(
predicate):ModelRef<T> |undefined
Defined in: packages/models/src/relations.ts:670
Find item by predicate
Parameters
predicate
(item, index, array) => boolean
the search predicate
Returns
ModelRef<T> | undefined
the found item, or undefined
findIndex()
findIndex(
predicate):number
Defined in: packages/models/src/relations.ts:679
Find index by predicate
Parameters
predicate
(item, index, array) => boolean
the search predicate
Returns
number
the index, or -1
forEach()
forEach(
callback):void
Defined in: packages/models/src/relations.ts:705
Execute callback for each item
Parameters
callback
(item, index, array) => void
the function to execute for each item
Returns
void
getModelRef()
protectedgetModelRef(model):ModelRef<T>
Defined in: packages/models/src/relations.ts:753
Convert any accepted input (string, key, ref, or model) into a ModelRef
Parameters
model
string | T | PrimaryKeyType<T> | ModelRef<T>
the input to convert
Returns
ModelRef<T>
the model reference
map()
map<
U>(callback):U[]
Defined in: packages/models/src/relations.ts:688
Map over items (does NOT mutate)
Type Parameters
U
U
Parameters
callback
(item, index, array) => U
the mapping function
Returns
U[]
the mapped array
pop()
pop():
ModelRef<T> |undefined
Defined in: packages/models/src/relations.ts:574
Remove and return the last item
Returns
ModelRef<T> | undefined
the removed item, or undefined
push()
push(...
items):number
Defined in: packages/models/src/relations.ts:553
Add items to the end of the collection
Parameters
items
...(string | T | PrimaryKeyType<T> | ModelRef<T>)[]
items to add
Returns
number
the new collection length
remove()
remove(
model):boolean
Defined in: packages/models/src/relations.ts:637
Remove item by reference or primary key
Parameters
model
string | T | PrimaryKeyType<T> | ModelRef<T>
the item to remove
Returns
boolean
true if the item was found and removed
set()
set(
items?):void
Defined in: packages/models/src/relations.ts:627
Set the collection to a new set of items
Parameters
items?
(string | T | PrimaryKeyType<T> | ModelRef<T>)[]
the new items to set
Returns
void
Webda Auto Setter
setDirty()
protectedsetDirty():void
Defined in: packages/models/src/relations.ts:770
Mark the parent model's property for this collection as dirty
Returns
void
shift()
shift():
ModelRef<T> |undefined
Defined in: packages/models/src/relations.ts:586
Remove and return the first item
Returns
ModelRef<T> | undefined
the removed item, or undefined
some()
some(
predicate):boolean
Defined in: packages/models/src/relations.ts:714
Check if any item matches predicate
Parameters
predicate
(item, index, array) => boolean
the test predicate
Returns
boolean
true if any item matches
splice()
splice(
start,deleteCount?, ...rest):ModelRef<T>[]
Defined in: packages/models/src/relations.ts:601
Remove/add items at specified index
Parameters
start
number
the start index
deleteCount?
number
number of items to remove
rest
...(string | T | PrimaryKeyType<T> | ModelRef<T>)[]
items to insert
Returns
ModelRef<T>[]
the removed items
toJSON()
toJSON():
PrimaryKeyType<T>[]
Defined in: packages/models/src/relations.ts:731
Convert to JSON
Returns
PrimaryKeyType<T>[]
array of primary key values
unshift()
unshift(...
items):number
Defined in: packages/models/src/relations.ts:564
Add items to the beginning of the collection
Parameters
items
...(string | T | PrimaryKeyType<T> | ModelRef<T>)[]
items to prepend
Returns
number
the new collection length