JayData.org

Configuring foreign keys for online-offline sync

Author: Robert Bonay February 25th, 2014

, , , , , ,


As you might know, JayData supports saving and querying related entities without joining the tables on foreign keys manually. If you haven’t tried it, start with JayData and relationship article.

This article will demonstrate the way to configure the name of foreign keys in the relationships.

Continuing the Northwind example in the mention article, you create a simple 1:N relationship between product and categories using the following JayData model definition.

After saving your entities using this data model, you end up with the database that has a Products table automatically filled Category__CategoryId column.

image

Although the auto-created foreign key is convenient, this behavior could make the development more difficult if you have an online-offline mobile application and want to implement data synchronization – for example over OData.

The configuration of foreign keys are very easy to change Category__CategoryId to the desired CategoryId column name – the definition of parent entity must be extended with the keys array property.

After modifying the data model and re-creating your database you will have a brand-new schema with your preferred foreign key.

image

Compatible versions: JayData 1.3.6+, JayData Pro 1.3.6+

Compatible storage providers: JayData API features (see the include/extend row)


, , , , , ,