---
title: Image affiliation
summary: Links an image to a business entity or claim context and manages the affiliation record's full CRUD lifecycle.
status: draft
owner: <owner>
last_reviewed: 2026-07-30
library: SAIF.Business.Imaging
reference_type: package
operation_id: OP-IMG-02
trigger: Caller creates, retrieves, updates, or deletes a clsImageAffiliation (or clsImageAffiliationCollection) instance
---

# Image affiliation

Image affiliation records associate an already-indexed image with a business entity or claim-related context, identified by an `AffiliationImageSeqNum`. The object supports the full CRUD lifecycle: a new affiliation gets a generated sequence number before insert, existing affiliations can be retrieved individually or as a collection scoped to an image, and updates/deletes operate by the affiliation's own sequence number.

| Field | Value |
| --- | --- |
| **Operation ID** | OP-IMG-02 |
| **Trigger** | Caller calls `clsImageAffiliation.NewImageAffiliation`/`Save()` to create, `GetImageAffiliation`/`clsImageAffiliationCollection.GetImageAffiliationCollection` to retrieve, or `Save()`/delete on an existing instance to update or remove |
| **Inputs** | `ImageSeqNum` (the image being affiliated), `AffiliationImageSeqNum` (the affiliated entity's key), and, for retrieval, `ImageAffiliationSeqNum` or `ImageSeqNum` |
| **Outputs** | Persisted `IMAGE_AFFILIATION` row (insert/update), a populated `clsImageAffiliation`/`clsImageAffiliationCollection` (retrieve), or row removal (delete) |
| **Primary components** | `clsImageAffiliation.BeforeCreate`, `clsImageAffiliation.BeforeInsert`, `clsImageAffiliation.BeforeRetrieve`, `clsImageAffiliation.BeforeUpdate`, `clsImageAffiliation.BeforeDelete`, `clsImageAffiliationCollection.BeforeRetrieve` |
| **Entry point** | `Business\SAIF.Business.Imaging\clsImageAffiliation.vb`, `Business\SAIF.Business.Imaging\clsImageAffiliationCollection.vb` |

## Steps

1. **Caller provides `ImageSeqNum` and affiliation context** (`AffiliationImageSeqNum`) to a new `clsImageAffiliation` instance via `NewImageAffiliation`.
2. **Validate required fields.** The registered rules require a non-zero `AffiliationImageSeqNum` (`IMAGEAFF1`) and a non-zero `ImageSeqNum` (`IMAGEAFF2`), checked on each property set.
   - On failure: a broken rule is added and blocks save until both keys are populated.
3. **Generate the sequence number.** `BeforeCreate` executes [SQL-001](../sql/SQL-001-saif-business-imaging.md) to obtain the next `IMAGE_AFFILIATION_SEQ_NUM` from `IMAGE_AFFILIATION_SEQ.nextval` ([DUAL](../database-tables.md#dual)); `AfterCreate` reads the scalar result into `ImageAffiliationSeqNum` and rebuilds the criteria object with it.
4. **Insert the affiliation row.** `BeforeInsert` sets `CreateUser` from the data-portal user ID and executes [SQL-004](../sql/SQL-004-saif-business-imaging.md) to insert into [IMAGE_AFFILIATION](../database-tables.md#image_affiliation), binding `AffiliationImageSeqNum`, `ImageAffiliationSeqNum`, `ImageSeqNum`, and `CreateUser`.
5. **Retrieve a single affiliation.** `BeforeRetrieve` executes [SQL-017](../sql/SQL-017-saif-business-imaging.md) by `ImageAffiliationSeqNum`; `AfterRetrieve` fills the object from the reader if a row is returned and marks it old.
6. **Retrieve all affiliations for an image.** `clsImageAffiliationCollection.BeforeRetrieve` executes [SQL-018](../sql/SQL-018-saif-business-imaging.md) filtered by `ImageSeqNum`; `AfterRetrieve` loads each row into a new `clsImageAffiliation` and adds it to the collection.
7. **Update an existing affiliation.** `BeforeUpdate` sets `CreateUser` again and executes [SQL-033](../sql/SQL-033-saif-business-imaging.md) to update `AffiliationImageSeqNum`, `CreateDate` (to `sysdate`), `CreateUser`, and `ImageSeqNum` for the row keyed by `ImageAffiliationSeqNum`.
8. **Delete an existing affiliation.** `BeforeDelete` executes [SQL-039](../sql/SQL-039-saif-business-imaging.md), removing the [IMAGE_AFFILIATION](../database-tables.md#image_affiliation) row keyed by `ImageAffiliationSeqNum`.
   - Note: `AfterInsert`, `AfterUpdate`, and `AfterDelete` are present as commented-out templates only; no rows-affected verification is performed after these operations in live code.*

## Process flow

The following diagram visualizes the image affiliation operation's create/retrieve/update/delete paths.

```mermaid
flowchart TD
	Start([Caller provides ImageSeqNum<br>and AffiliationImageSeqNum]) --> Which{Which action?}
	Which -->|Create| Validate[Validate: keys non-zero]
	Validate --> VOk{Rules pass?}
	VOk -->|No| Fail([Broken rules returned])
	VOk -->|Yes| GenSeq[BeforeCreate: generate<br>IMAGE_AFFILIATION_SEQ_NUM]
	GenSeq --> Insert[BeforeInsert: INSERT row]
	Insert --> Done([Affiliation created])
	Which -->|Retrieve one| RetrieveOne[BeforeRetrieve by<br>ImageAffiliationSeqNum]
	RetrieveOne --> DoneR([Affiliation loaded])
	Which -->|Retrieve collection| RetrieveAll[BeforeRetrieve by<br>ImageSeqNum]
	RetrieveAll --> DoneRC([Collection loaded])
	Which -->|Update| Update[BeforeUpdate: UPDATE row]
	Update --> DoneU([Affiliation updated])
	Which -->|Delete| Delete[BeforeDelete: DELETE row]
	Delete --> DoneD([Affiliation deleted])
```

## Failure and edge-case behavior

- `AfterInsert`, `AfterUpdate`, and `AfterDelete` on `clsImageAffiliation` are present only as commented-out template code, so no rows-affected concurrency check runs after these operations; a failed insert/update/delete may go undetected by this class.*
- The required-field rules (`IMAGEAFF1`, `IMAGEAFF2`) run on every property set, not gated by a dirty check, so they apply uniformly to new and loaded instances.

## Related documentation

- [Operations and processes](../operations-processes.md)
- [Business rules](../business-rules.md)
- [SQL catalog](../sql/index.md)
- [Database tables](../database-tables.md)

> **Note:** Statements marked with `*` were inferred from code structure, naming
> conventions, or contextual evidence where direct confirmation was not available
> in source artifacts.

## Sources

- `Business\SAIF.Business.Imaging\clsImageAffiliation.vb`
- `Business\SAIF.Business.Imaging\clsImageAffiliationCollection.vb`
