LogoRobo.js
Framework

JunctionTableManager

Class: JunctionTableManager

Junction table manager for many-to-many relationships.

Provides methods to add, remove, and query junction table entries.

Constructors

new JunctionTableManager()

new JunctionTableManager(adapter, getModel): JunctionTableManager

Parameters

ParameterType
adapterFlashcoreAdapter<string, unknown>
getModel(name) => unknown

Returns

JunctionTableManager

Methods

addRelation()

addRelation(
   sourceModel, 
   sourceId, 
   targetModel, 
targetId): Promise<void>

Add a relationship between two records. Uses compound unique constraint to prevent duplicates.

Parameters

ParameterTypeDescription
sourceModelstringSource model name
sourceIdstringSource record ID
targetModelstringTarget model name
targetIdstringTarget record ID

Returns

Promise<void>

Throws

UniqueConstraintError if relationship already exists


getRelatedIds()

getRelatedIds(
   sourceModel, 
   sourceId, 
targetModel): Promise<string[]>

Get all related IDs through a junction table.

Parameters

ParameterTypeDescription
sourceModelstringSource model name
sourceIdstringSource record ID
targetModelstringTarget model name

Returns

Promise<string[]>

Array of related record IDs


removeAllRelations()

removeAllRelations(model, recordId): Promise<number>

Remove all relationships for a record (used in cascade delete).

Parameters

ParameterTypeDescription
modelstringModel name
recordIdstringRecord ID

Returns

Promise<number>

Number of relationships removed


removeRelation()

removeRelation(
   sourceModel, 
   sourceId, 
   targetModel, 
targetId): Promise<boolean>

Remove a relationship between two records.

Parameters

ParameterTypeDescription
sourceModelstringSource model name
sourceIdstringSource record ID
targetModelstringTarget model name
targetIdstringTarget record ID

Returns

Promise<boolean>

True if relationship was removed, false if it didn't exist


setRelations()

setRelations(
   sourceModel, 
   sourceId, 
   targetModel, 
targetIds): Promise<void>

Set relationships to exactly the given IDs (replaces existing).

Parameters

ParameterTypeDescription
sourceModelstringSource model name
sourceIdstringSource record ID
targetModelstringTarget model name
targetIdsstring[]Array of target record IDs

Returns

Promise<void>

On this page