Entity Table Configuration

Entity tables are tables that are related to an entity in a one-to-one relationship.

One-to-one relationships between entities and tables are rare. For example, in a database setting, such a relationship could be implemented by simply adding the attributes from one table to the other (with appropriate setting of not null/null constraints).

A one-to-one relationship can be thought of as a subset of the more general many-to-one relationship which also includes the zero-to-one relationship.

Address Relationship

An example of a one-to-one relationship is where a selection held against our graffiti entity links each selected value to a single, optional, street address. With that street address being stored in an external table.

We can think about this relationship from two perspectives:

  • From the perspective of a single piece of graffiti there is recorded against it, a single, optional, street address (it is optional as the graffiticould be in a public park).

  • From the perspective of the street address, multiple pieces of graffiticould exist there, but it is the perspective of the piece of graffitithat determines our one-to-one relationship. (This will mean that a single street address will be duplicated if two pieces of graffitiare located at the same address: this is addressed later on in this documentation.)

The following implement this editor.

  1. Create apublic.graffiti_address table to hold the one-to-one data.

DROP TABLE IF EXISTS public.graffiti_address; CREATE TABLE public.graffiti_address ( id serial not null primary key, graffiti_id int unique, street_address varchar(100), city_suburb varchar(100), postcode varchar(4), state varchar(50) ); /* graffiti_id will be same as graffiti id. Unique constraint ensures only 1 address record per graffiti item */ ALTER TABLE public.graffiti_address ADD CONSTRAINT address_graffiti_fk FOREIGN KEY (graffiti_id) REFERENCES public.graffiti (id);
  1. Definition for graffiti entity (already defined in spatial editing documentation).

<entity:entity id="graffiti" label="Graffiti" />
  1. Configure the graffitientity as a spatial entity.

<mapper:mapper id="m.graffiti"> <spatialengine>se.postgresql</spatialengine> <mapping entity="graffiti"> <table>public.graffiti</table> <key>id</key> </mapping> </mapper:mapper>
  1. Associate the graffitientity with a data definition.

  1. Visualise the relationship as a database relationship (where, for the purpose of this example, the entity graffiti is associated with the table public.graffiti in some way).

A graffiti entity can have zero or one addresses associated with it.
  1. Create the edit configuration.

To allow Weave to use the relationship when editing the graffiti entity, we first need to define an editor for it.

The osgi editor conf command can be used to generate a configuration. Once generated the editor type needs to be changed from table to entity and the entityattribute set to the name of the entity that the table rows represent (in our case graffiti).

Notes:

  • Each table in Weave has always has to have its own primary key.
    For public.graffiti_address the <key> attribute value isid.
    This attribute is optional and will be set if there's a single column primary key on the table.

  • The <entitykey> attribute whose underlying column graffiti_id will contain the value that links an address to a parent entity. It is insufficient to just have the <entitykey> attribute set to graffiti_id. A parameter (id='graffiti_id') needs to be defined for the entitykeywith its value attribute set to entitykey(). This function will extract from the selected entity its idvalue and write it to the associated column.

  1. Check that the editor has been created via use of the Config application within the Admin tool:

Check that Entity Editor has been created.
  1. To use the entity editor, we can use the editor.panel.simplegrid panel by adding the following to the client (XML).

The client will then look something like this:

 

 

Entity Selection

To edit address data we first need to select a graffiti entity.

Spatial Entity Selection

Because the graffiti entity has associated with it a <mapper> we can select a graffiti entity via the layer in the Weave client.

Non-Spatial Entity Selection

Because the graffiti entity has associated with it a data definition, we could select a graffiti entity via an attribute selection.

Working With an Entity Selection’s One-to-One Data

Once a selection is made against the graffiti entity, in the following tab either a row will appear (if an address exists for the entity) or not (if the selected entity has no street address).

To create a record for the selected piece of graffiti, press Create and a form will appear. Then enter the data.

Pressing Submit will cause the record to be saved to the database and shown in the grid.

Any edits of the grid record will cause the (1:1) record in the database to be replaced.

Deleting the address is simply a matter of selecting the address (row) and pressing Delete.

 

 

  1. An alternate to the grid editor for our address data is a form-based editor, editor.panel, which can be added to our client XML as follows.

Since we have just deleted the selected graffiti entity’s address, no data appears in the form.

Adding address data to the selected graffiti entity is done by entering the data directly into the form and pressing Submit.

 

 

Notice that the newly created address has invalidated the entity selection. To view the data, reselect the graffiti entity.

To edit an existing address simply change the data in the form and press Submit. This will cause the existing database record to be overwritten.