> For the complete documentation index, see [llms.txt](https://ecfmg.gitbook.io/azure-serverless-quickstart/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://ecfmg.gitbook.io/azure-serverless-quickstart/patterns-and-practices/ddd/field-types/non-primitive-types/populateddoc.md).

# PopulatedDoc

### Cosmos DB Model

{% code title="/infrastructure/data-sources/cosmos-db/models/physician.ts" %}

```typescript
updatedBy: PopulatedDoc<Account>;
```

{% endcode %}

### Domain Props

{% code title="/domain/contexts/physician/physician.ts" %}

```typescript
readonly updatedBy: AccountProps;
setUpdatedByRef: (updatedBy: AccountEntityReference) => void;
```

{% endcode %}

* Every PopulatedDoc field needs the read-only field with props type and a setRef field which is a method that takes in an entity reference of the domain object referenced in previous field
* The argument of setRef method should be the same as the name of the field above it

### Domain Entity Reference

{% code title="/domain/contexts/physician/physician.ts" %}

```typescript
export interface PhysicianEntityReference 
extends Readonly<
    Omit<
        PhysicianProps,
        "updatedBy" | "setUpdatedByRef"
        >
    > {
    readonly updatedBy: AccountEntityReference;
}
```

{% endcode %}

* Note: must include field name and setRef method name in the omit union of strings

### Domain Class

#### Getter

{% code title="/domain/contexts/physician/physician.ts" %}

```typescript
get updatedBy(): AccountEntityReference {
    return new Account(this.props.updatedBy, this.context);
}
```

{% endcode %}

#### Setter

{% code title="/domain/contexts/physician/physician.ts" %}

```typescript
public requestSetUpdatedBy(updatedBy: AccountEntityReference) {
    this.setUpdatedByRef(updatedBy);
}
```

{% endcode %}

* setRef method comes from field defined in Domain Props
* Note: setRef method takes in entity reference of domain object as an argument

### Domain Adapter

#### Getter

{% code title="/domain/infrastructure/persistence/physician.domain-adapter.ts" %}

```typescript
get updatedBy(): AccountProps {
    if (this.doc.updatedBy) {
        return new AccountDomainAdapter(this.doc.updatedBy);
    }
}
```

{% endcode %}

#### Setter

{% code title="/domain/infrastructure/persistence/physician.domain-adapter.ts" %}

```typescript
setUpdatedByRef(updatedBy: AccountEntityReference) {
    this.doc.set("updatedBy", updatedBy["props"]["doc"]);
}
```

{% endcode %}

* Needs a setter for the setRef method created in domain props
* takes in entity reference of domain object being stored in that field
* Note: use exactly the notation below for setting the doc: first argument is the field name as a string and the second is the argument being passed in to the function with square bracket notation accessing the doc of that domain object


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://ecfmg.gitbook.io/azure-serverless-quickstart/patterns-and-practices/ddd/field-types/non-primitive-types/populateddoc.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
