Back to blog

BGDatabase v.1.7.5 Views and view relational fields

05/2022

Introducing views and view relational fields

BGDatabase v.1.7.5 introduced views and 2 new view relational fields: viewRelationSingle and viewRelationMultiple as better alternatives to manyTablesRelationSingle and manyTablesRelationMultiple fields

What is a view?

The view is a virtual table, which does not have its own rows. It contains a set of table references and its own set of fields. Each included table should have the same set of fields (with the same names and types).

What are view relational fields?

View relational fields are the fields, referencing the rows from the view. They are similar to manyTablesRelationSingle and manyTablesRelationMultiple, allowing to reference rows from multiple tables

Why view relational fields are better alternatives to many tables relational fields?

  1. View is a persistent structure. You can reference the same view from multiple tables. With many tables relational fields - you need to define the set of tables, you reference, for each field
  2. CodeGen addon generates one single interface for each view. Each included table implements this interface and all view relations, referencing the view reuse this view interface as its value type. For many tables relational fields- codegen addon generates interfaces for each field, and it's a big disadvantage if you want to reference the same set of tables

Migrate from many tables relational fields to view relational fields

Internal data format for these fields is compatible, so it's easy to switch to view relational field without losing any data. The guide below is for manyTablesRelationSingle->viewRelationSingle conversion.

  1. Back up database file(s) just in case
  2. Create a view, add required fields and include tables
  3. Select manyTablesRelationSingle field and make sure it has the same set of tables in the field's settings
  4. Open up field's menu by clicking on "M" menu button and choose "Change file type"
  5. Select viewRelationSingle as target field type, select a view and click on "Change field type" button
  6. Review the changes under database tab to make sure all values remain intact, press on "Save" to commit or "Reload" to rollback

Example project

The inventory example project uses views and views relational fields