===== Defining relations in a Vortex instance ===== This guide will show you how to setup and define relations between tables in a Vorted DBI. === Requirements === * A working Vortex DBI * At least two tables to create relations between, here called //Table1// and //Table2// * Knowledge on how to create and edit records in the Vortex === Overview === In the Vortex there are three types of relations between tables. * 1-1 relations, where one record in Table1 refers to exactly one record in Table2, for instance one social security number relates to a person in this way, as one person can only have one number and one number only refers to that same person * 1-x relations, where one record in Table1 refers to many records in Table2, but where that record in Table2 only refers to the one record in Table1. For example a person relates to cars in this way, where one person can own many cars but a car can only have one owner. * x-x relations, where many records in Table1 referes to many records in Table2. For example users relate to groups in this way where one user can relate to many groups, and one group to many users === Relation fields === For the first two relation types, 1-1 and 1-x, the record on the 1-side contains a field pointing to the related record, where the record on the x-side doesn't have this field but instead has a list of related records. * For 1-1 relations, both sides has a relation field * For 1-x relations, the 1-side record has a relation field To create a relation field, simply create a field in the table of type //Relation// and give it a suiting name and description. === Setting up the relation === When the required tables and fields are created, open the //Admin// menu and choose //Relations//. {{ :vortex:examples:vortex_11.png?600 |}} An in detail description of relations is given [[vortex:usermanual&#relations_administration|in the User Manual]] - Choose the first table in the //Table1// column - Enter a name for the first table in //Name1//, ie what is related, would be //owner// if Table1 was a car having one owner - Enter a description for the first table in //Description1//, would be //My Owner// in the example above - Choose the second table in the //Table2// column - Enter an name for the second table in //Name2//, would be //cars// in the example above - Enter a description for the second table in //Description2//, would be //Cars owned by person// in the example - Choose a type in the //Type// dropdown list, for the cars/owner example above this would be 1-x - If the type is 1-1 or 1-x, choose the related field in //Field1//, would be the //owner// field in the //car// table in the example. Choose this by right-clicking the //i// symbol and choosing //Field//, only relation fields are shown in the list. - If the type is 1-1, choose the related field from the second table in //Field2// Observe that it is very important that the right field for the right table is chosen in the //Field// columns, otherwise behaviour of theese tables will be erratic! Saving the relation makes the connection between the tables active.