Related Records

How do we link related records into an entity?

In earlier versions of GoZync, you included related records in a portal on your sync layout and GoZync knew you wanted to include those related records in the same transaction as the parent sync layout. So if you were syncing an invoice, your sync layout included a portal of invoice line items.

That worked but was slower that it needed to be.

Starting in GoZync 4, each table you sync--related or parent gets its own sync layout.

You then use the Configuration tab in GoZyncHosted to indicate which tables are related to each other. Starting at the "child" table, click "edit" and then pick the table it is related to. (See the first screenshot below.)

You'll then be asked which field links the child table to the parent. You're being asked for the foreign key field in the child table: in our example, the related table is called "Invoice Data" and contains the invoice line items. It is related to Invoices and there is a field in each invoice line item that holds the primary key (the unique ID) of the invoice that line belongs to. That field is called "InvoiceData::Invoice ID" in our example and if you looked at the relationships in FileMaker it would be linked to the invoice's primary key: "Invoices::ID".

Be sure to click "edit" and fill out the screen above for both sides (hosted and mobile) of the table's row on the Configuration tab of GoZyncHosted.

When you're done you'll see the Configuration tab indent "related" tables below their parents, and indicate how they are related.

How do I undo a relationship and go back to syncing the table on its own?

Simply click in the "requires" column for that row and then click the "clear & cancel" button in the lower left of the "Requires...". That will undo the "requires" setting; do this on both the hosted and mobile sides of the table's configuration row and it will no longer be indented on the configuration tab and will be synced as its own table (provided you call a script to Zync it, or run "Zync It - Everything".

Syncing "Grandchildren"

Related syncing in GoZync only goes one "level" deep. It doesn't support synching of "grandchildren" (the engine would have to be exponentially more complex). In the case of three tables where the third is the grandchild of the first you'll have to choose one of those relationships for related synching and sync the third table independently.

What about related Join Tables or table with more than one foreign key?

The use case around join tables looks like this: imagine you have a table of addresses that is related to (that is a child of) both Companies and Contacts. Once you've wired up Addresses in GoZync mobile you can ask it to "require" either Companies or Contacts, but not both. So how can you set it up so when you sync a company or a contact you always get their addresses?

Here's how:

Option 1. To sync it as a transaction you'd create a new pair of table occurrences (TOs) for Address in GoZyncMobile and a two new layouts for this "Address2" TO. These new TOs can then require Contact and be children of it. One downside here is that you may sync some address records more than once if they're related to both a contact and a company which was changed since the last sync. Not a data integrity issue, but it's doing more sync work than absolutely necessary, though on a narrow table like Address that's probably not a big deal.
The other downside is that this doesn't work for pull, only for pushing: if you're pulling as well you'll want to do what we're suggesting as option 2 below.
Option 2. The second option would be not to require any parent for Address and sync the table you have on its own. The script "Zync It - Public API - ( TOName ) { Action ; RecordID }" in GoZyncMobile can take a list of Table Occurrence names as a parameter (read the head of that script for notes on the syntax) so you could script it so the "sync companies" button in your file sent a list to "Zync It..." that included Companies and Address. The only downside here is that when syncing Address you'll send / receive any changed address record, even if the creation of a contact record caused it. So if you never synced the contacts table, or synced it infrequently, you could get Address records for a contact you haven't received yet. Again, not a data integrity issue but maybe your sync button would include the TO Names for Contact, Company, and Address just to prevent this.
Follow us: