After reading this article you will know:
- What subviews are and how they appear
- What they are used for in your application
- When they appear as forms or as grids
Models stored in the data model are relational to one another. A view displays a model with its data. Thanks to the use of model relations, it is possible to navigate through your back office information by using views with subviews.
A subview is a related view to a source view, based on the model relation the two models has. Example: you have created a customer grid in your back office. On the form, which displays a single customer object, you would like to navigate through related customer information. This could be the customer's invoices, address, contact moments, etc. In this case, invoices, address, and contact moments are the customer's subviews.
Subviews could appear in two ways: as grids or as forms. This distinction is based on the type of relation between two models.
Subviews appear as grids when the type of model relation is set as has many or has and belongs to many. This means that one object from the source model is related to more objects from the target model. Example: your customer has many invoices. The subview 'invoices' on the customer's form is shown as a grid. Why? Because one customer object is related to more invoice objects (invoices).
Subviews appear as forms when the type of model relation is set as belongs to. This means that one object from the source model is related to one object from the target model. Example: every invoice belongs to one customer. The subview 'customer' is now shown as a form. Why? Because one invoice object is related to one customer object.