Martini Data Model References
Overview
Data Model References allow you to reuse existing data models across multiple services, workflows, and other data models. This feature enables modular design by letting you extend models or add them as properties, promoting consistency and reducing maintenance overhead across your Martini packages.
What You Will Learn
By the end of this guide, you'll understand how to:
- Reference existing data models to avoid duplication
- Navigate between models that use references and the models being referenced
- Track model usage across your Martini workspace
When To Use This
Use Data Model References when you need to:
- Reuse and extend data models
- Maintain consistency and reduce duplication
- Ensure changes to core models automatically propagate to dependent components
Prerequisites
- Martini Designer installed and running
- A Martini Package in the active workspace
- Data Models in the package
- Basic understanding of the Data Model Editor
- Basic understanding of Service Inputs & Outputs
- Basic understanding of Workflow Inputs & Outputs
Referencing Data Models
Data model referencing creates relationships between data models, allowing one model to inherit the structure and properties of another. This creates a powerful system for building reusable, maintainable data architectures within your Martini packages.
Getting Started with Setting Model References
Data model references can be set in a Data Model Editor or in the Input/Output panel of a Service or Workflow. In these locations, you can use the following methods:
Configuration View Method:
- Open the Configuration view for either the root model or one of its model properties
- In the Reference field, search for the name of the data model you want to reference
- Choose the desired data model from the search suggestions
Drag-and-Drop Method:
- Open the Navigator view
- Locate the Data Model you want to reference
- Drag and drop it to the desired position in the editor or input/output panel
Content Assist Method:
- In the editor or input/output panel, press . to trigger content assist
- Type the name of the data model you want to reference
- Select the model from the suggestions list to add it as a property
Expected result: The model will now include the child properties of the data model it's referencing.
Referencing Models from Other Martini Packages
Data model references are not limited to data models within the same package. By configuring package dependencies, you can reference data models from other packages using the same methods described above:
- Configuration View Method: Search for data models from dependent packages in the Reference meta-property
- Drag-and-Drop Method: Drag data models from dependent packages in the Navigator view
- Content Assist Method: Use content assist to find and select data models from dependent packages
How Data Model References Work
Data model references create dynamic relationships between data models through namespace resolution. When you reference a data model, Martini automatically includes all properties from the source model and keeps them synchronized with any changes.
Visual Indicators:
- Reference Label: Model properties that reference another data model display the referenced model name in parentheses next to the property name (e.g.,
customerInfo (Customer)) - Lock Icons: Child properties inherited from referenced data models show a icon overlay, indicating they are read-only
- Property Inheritance: All properties from the referenced data model appear as child elements under the referencing property
Dynamic Updates:
When you modify the source model, changes propagate immediately to all models that reference it. This ensures consistency across your entire Martini package without manual updates.
Navigating Between Referenced Models
You'll often need to modify source definitions or track where models are being used throughout your workspace. Martini provides several methods to navigate between referenced models and their sources.
Editing Source Model Definitions
To modify properties that are inherited from referenced data models, you must access the original source model. Use any of the following methods to quickly jump to the source model:
Context Menu Method:
- Right-click on the model property
- Select Open Declaration from the context menu
Keyboard Shortcut Method:
- Select the model property
- Press Ctrl + Shift + Enter (Windows/Linux) or Cmd + Shift + Enter (macOS)
Expected result: The referenced model opens in a new Data Model Editor tab, allowing you to modify the original definition. Changes will automatically propagate to all referencing models.
Finding Data Model Usage Across Your Workspace
To understand where a data model is being referenced throughout your workspace:
- Open the Navigator view
- Locate the Data Model you want to analyze
- Right-click on it and select Find References
Expected result: Search results display locations where the model is referenced.
Data Model Reference Benefits and Use Cases
Data model references solve the problem of data structure duplication and maintenance overhead in large Martini packages. By creating reusable model definitions, you ensure consistency and reduce the effort required to maintain complex data architectures.
Key Benefits:
- Consistency: Changes to core models automatically update all dependent structures
- Maintainability: Single source of truth for common data patterns reduces maintenance overhead
- Modularity: Build complex data structures from simple, reusable components
- Team Collaboration: Share standardized data models across different teams and package modules
Use Cases:
- Address Models: Reuse address structures across customer, vendor, and shipping models
- Audit Fields: Include common fields like
createdAt,updatedAt, andcreatedByacross multiple entities - API Response Wrappers: Standardize response formats with common metadata properties
Troubleshooting Data Model Reference Issues
| Problem | Detection | Cause | Fix |
|---|---|---|---|
| Stack overflow when opening model | Stack overflow error is thrown during model load | Circular model referencing between models | Correct the Reference meta-property of involved models to avoid circular dependency |
| Referenced properties disappeared | Reference meta-property has value but no child properties show | Referenced model no longer exists | Reset the Reference meta-property or set it to reference an existing model |
| Model-not-found error at runtime | Error occurs when using model despite properties being present | Referenced model is not in same package or package dependencies | Reference a model within the package/dependencies or add the referenced model to package dependencies |
Helpful Resources
- Data Model Property Types - Understanding different data model property types
- Normalizing Data Models - Guidelines for designing data models
- Community Q&A: Martini Community
Have a Question? Post or search it here.