Skip to content

Commit ca89edc

Browse files
authored
node vs. generic (#5765)
* node vs. generic * add link
1 parent b49bf23 commit ca89edc

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

docs/docs/topics/schema.mdx

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,28 @@ To help with the development process of a schema definition file, you can levera
2525

2626
## Schema definition
2727

28-
### Namespace, Node, Attributes, Relationships, and Generics
28+
### Node, Attributes, Relationships, and Generics
2929

3030
The schema is composed of 4 primary types of objects: `Nodes`- that are themselves composed of `Attributes` and `Relationships` and finally `Generics`.
3131

32-
- A `Node` in Infrahub represents a `Model`.
32+
- A `Node` in Infrahub represents a `Model`. Nodes are instances of a specific object within your infrastructure. Nodes have attributes that define specific values, such as text or numbers, and relationships that link them to other nodes.
3333
- An `Attribute` represents a direct value associated with a `Node` like a `Text`, a `Number` etc ...
3434
- A `Relationship` represents a link between 2 `Node`, a `Relationship` can be of cardinality `one` or `many`.
35-
- A `Generic` can be used to share some attributes between multiple `Node`, if you're familiar with programming concept, it's close to class inheritance.
35+
- A `Generic` can be used to share attributes and relationships between different types of `Node`s. They can connect multiple types of nodes to the same relationship or define attributes and relationships on a specific list of nodes. Generics are similar to class inheritance in programming languages like Java or Python.
36+
37+
### Nodes vs. Generics
38+
39+
Use a `Node` when you need to represent a concrete object in your infrastructure model with specific attributes and relationships.
40+
41+
Use a `Generic` when you want to share common attributes or relationships across multiple node types. This helps to avoid redundancy and ensures consistency across your schema. For example, if you have different types of network interfaces (physical, logical) that share common attributes like name and description, you can define a `Generic` interface with these attributes and have the specific interface types inherit from it.
42+
43+
`Generic`s can also be used to connect multiple types of Nodes to the same relationship.
44+
45+
When deciding between a `Node` and `Generic`, remember that computed attributes can only be used on `Nodes`, not `Generics`.
46+
47+
If a `Generic`'s properties are updated after the `Node` has been created, these updates will not be propagated to the `Node`; users must manually update `Nodes` if they want to reflect changes made to `Generic`s. See [Inherited properties](#inherited-properties) for more information.
48+
49+
### Node example
3650

3751
In the example below, the node `Person` has 2 attributes (`name` and `description`) and the node `Car` has 1 attribute (`model`) and 1 relationship to `Person`, identified by `owner`.
3852

0 commit comments

Comments
 (0)