Skip to content

Relations with Data Objects

Backendless Data Service manages application's data objects and provides APIs to work with data objects. Backendless provides integration between data objects managed by Data Service and geo points managed by Geo Service for the scenarios when a logical connection between the two types must exist in an application. For instance, in a taxi ordering app a data object may represent a taxi car, while a geo point represents its location on the map. It is logical to link the two together so they can be retrieved and managed at once.

The Geo-to-Data integration is implemented through geo point metadata. A metadata property may reference one or more data objects. These relations may be created using the API or with Backendless Console. Once a relation is established, the console displays it in the Metadata column as a link to related data object(s). When a geo point is retrieved using the API, any related data objects can be retrieved by using the same principle for loading geo point metadata. The geo-to-data relation is bidirectoral, that is, a data object may reference a geo point through object properties (table columns). You can learn more about it in the Relations with Geo Points section of the Data documentation.

Apart from linking with the data objects, you can also link a geo point with a user object. Establishing relations with a user objects is performed the same way as with a data object.

Establishing Relations with a Data Object via Console

To link a geo point with a data object:

  1. Click the Geolocation icon to open the Geo location screen.
  2. Select a geo category to get a list of geo points from it.
  3. Click the plus icon for a geo point you want to link with a data object.
    geofence-screen10.zoom50
  4. The Add Related Object pop-up window will display.
  5. Type in a metadata property name in the Property field. This is the name of a new metadata property which will point to a related data object:
    geofence-screen11.zoom70
  6. Select a data table from from the Table drop-down menu. If you want to establish relation with a user object, select the Users  table from the drop-down menu. A list of the data objects which belong to the selected table will display.
  7. Select the check-boxes for the data object(s) you want to link the geo point with.
  8. Click the Add Related Objects button to establish a relation and save the changes.

Once a relation is established, the name of the property and the related data table name will display for the geo point:

geofence-screen12.zoom50

Updating/Deleting Relations

You can update or delete a geo to data relation by following the same process as above. The only difference is in order to access the"relation management" popup click the yellow box identifying the relation:

Create a Geo to Data Relation with the API

Creating a relationship between a geo point and data objects uses the same API as saving a geo point with metadata. The data object referenced in the metadata is saved in a table in the Data Service storage.

The example below adds a geo point representing a location of a taxi cab. The geo point includes the "TaxiCab" metadata property which references an object from the TaxiCab data table. This is an example of a one-to-one relation (one geo point is related to one data object).

Create a one-to-one relation:
HashMap cab = new HashMap();
cab.put( "make", "Ford" );
cab.put( "model", "Crown Victoria" );
GeoPoint pickupLocation = new GeoPoint( 40.750549, -73.994232 );
pickupLocation.addCategory( "Pickups" );
pickupLocation.addMetadata( "TaxiCab", cab );
Backendless.Geo.savePoint( pickupLocation );
Or a one-to-many relation:
HashMap cab1 = new HashMap();
cab1.put( "make", "Ford" );
cab1.put( "model", "Crown Victoria" );

HashMap cab2 = new HashMap();
cab2.put( "make", "Toyota" );
cab2.put( "model", "Prius" );

List<HashMap> availableCabs = new ArrayList<HashMap>( );
availableCabs.add( cab1 );
availableCabs.add( cab2 );

GeoPoint pickupLocation1 = new GeoPoint( 40.750549, -73.994232 );
pickupLocation1.addCategory( "Pickups" );
pickupLocation1.addMetadata( "AvailableCabs", availableCabs  );
Backendless.Geo.savePoint( pickupLocation1 );;
First, declare the TaxiCab class:
public class TaxiCab
{
  private String carmake;
  private String carmodel;
  private GeoPoint location;
  private List<GeoPoint> previousDropOffs;

  public String getCarmake()
  {
    return carmake;
  }

  public void setCarmake( String carmake )
  {
    this.carmake = carmake;
  }

  public String getCarmodel()
  {
    return carmodel;
  }

  public void setCarmodel( String carmodel )
  {
    this.carmodel = carmodel;
  }

  public GeoPoint getLocation()
  {
    return location;
  }

  public void setLocation( GeoPoint location )
  {
    this.location = location;
  }

  public List<GeoPoint> getPreviousDropOffs()
  {
    return previousDropOffs;
  }

  public void setPreviousDropOffs( List<GeoPoint> previousDropOffs )
  {
    this.previousDropOffs = previousDropOffs;
  }
}
Create a one-to-one relation:
TaxiCab cab = new TaxiCab();
cab.setCarmake( "Ford" );
cab.setCarmodel( "Crown Victoria" );
GeoPoint pickupLocation = new GeoPoint( 40.750549, -73.994232 );
pickupLocation.addCategory( "Pickups" );
pickupLocation.addMetadata( "TaxiCab", cab );
Backendless.Geo.savePoint( pickupLocation );
Or a one-to-many relation:
TaxiCab cab1 = new TaxiCab();
cab1.setCarmake( "Ford" );
cab1.setCarmodel( "Crown Victoria" );

TaxiCab cab2 = new TaxiCab();
cab2.setCarmake( "Toyota" );
cab2.setCarmodel( "Prius" );

List<TaxiCab> availableCabs = new ArrayList<TaxiCab>( );
availableCabs.add( cab1 );
availableCabs.add( cab2 );

GeoPoint pickupLocation1 = new GeoPoint( 40.750549, -73.994232 );
pickupLocation1.addCategory( "Pickups" );
pickupLocation1.addMetadata( "AvailableCabs", availableCabs  );
Backendless.Geo.savePoint( pickupLocation1 );;