After completing this unit, you’ll be able to:
This article contains several examples of writing geodatabase relationship classes. It includes demos for concepts covered in the previous unit, Working with Geodatabase Relationship Classes. Examples cover 1:M relationships, inserting into a M:N M:N or attributed relationships, and advanced M:N relationships.
We assume we have already created the relationships in ArcGIS for the following examples. Making them that way is required, as FME cannot create the relationships but merely populate them.
This unit’s exercise uses the Esri Geodatabase (File Geodb) reader/writer, which requires a licensed version of ArcGIS. For more information on required ArcGIS license levels, please see Required ArcGIS License Types for FME Geodatabase Formats.
As mentioned in the previous unit, when dealing with a 1:M relationship class, there is no intermediate table to keep track of these relationships. The relationships are bound to each other through the primary and foreign keys.
1. Open FME Workbench
Open FME Workbench (2021.1 or later) and start a blank workspace. Add an Esri Geodatabase (File Geodb) reader to the canvas and browse to the 1ManyRelationshipStart.gdb. There are no additional parameters to set for this reader, so click OK.
In the Select Feature Types dialog, select both feature classes (A_A_Parcels and A_Neighborhoods) and click OK.
2. Create geodb_feature_has_relationships Attribute
Add an AttributeCreator to the canvas and connect it to the A_A_Parcels reader feature type. In the parameters, create a new attribute geodb_feature_has_relationships with the value of yes. Next, create another attribute called geodb_oid, set it to the attribute OBJECTID, and click OK.

Duplicate the AttributeCreator (ctrl-d or ⌘-d) and connect it to the A_Neighborhoods reader feature type.

3. Write to Geodatabase
Add an Esri File Geodatabase (File Geodb) writer to the canvas and select a folder for the output. For this example, we named the geodatabase 1_to_many.gdb. Set the Feature Class or Table Definition to Import from Dataset, then open the Parameters.

In the Parameters, enable Overwrite Existing Geodatabase, then for Import XML Workspace Document (Schema Only) browse to the XMLWORKSPACETEMPLATE.XML. Click OK twice to add the writer.

In the Import Writer Feature Types dialog, change the format to Esri Geodatabase (XML Workspace Document), then browse to the XMLWORKSPAPCETEMPLATE.XML.

In the Select Feature Types dialog, select both the feature types and click OK.
Connect the writer feature types to their corresponding AttributeCreators.
4. Save and Run the Workspace.
Save the workspace, then run it. Open the geodatabase in ArcCatalog; you should see which features are related. Here is an example for ParcelID: 144. It is related to the Kitsilano Neighborhood.
Sometimes, the data in the origin and destination feature classes already exist, and you want to add the relationships to the relationship table. You can do this if:
To add the relationships, set the geodb_type to geodb_relationship or geodb_attributed relationship (if attributed) and the geodb_rel_origin_oid and geodb_rel_destination_oid to their respective OBJECTIDs. This does require that FME reads the feature classes which participate in the relationship but does not involve writing them out again. You only need to write to the relationship table in this case.
1. Review Geodatabase in ArcGIS
Before we create the relationship in FME, let’s review the data structure in ArcCatalog. Open Esri ArcCatalog, and navigate to the Many2ManyInput.gdb file from the Resources zip file. We will use this geodatabase in FME.
Looking at the geodatabase, we can see two tables (Structure and ADDRESS) and a relationship class (Structure_to_Address_rel).
Here you can see that the relationship class already exists. You can learn more about the relationship by opening the properties of the relationship class in ArcGIS. Right-click the Structure_to_Address_rel relationship class > Properties. As a reminder, you must create relationship classes in ArcGIS and then populate them using FME.
2. Add Geodatabase to FME Workbench
Now that we’ve inspected our geodatabase in ArcGIS and know the relationship we are working with, we can move to FME Workbench. Open a blank workspace in FME Workbench (2021.1 or later). Add an Esri Geodatabase (File Geodb) reader to the canvas and browse to the Many2ManyInput.gdb dataset, then click OK.
In the Select Feature Types dialog, select only ADDRESS and Structure, then click OK.

3. Modify Attributes to Reflect Relationship Class
Because this is a M:N relationship, we need to ensure FME will write the features to the relationship class with the required attributes:
geodb_rel_origin_oid : the ID attribute from the related origin feature.geodb_rel_destination_oid : the ID attribute from the related destination feature.geodb_type : either geodb_relationship or geodb_attributed_relationship.The Origin and Destination oids refer to the primary and foreign keys on the respective feature classes. In this example, we used the ObjectID as the value for the newly created origin/destination oid.
Add an AttributeCreator to the canvas and connect it to the ADDRESS reader feature type. In the parameters, create a new attribute called geodb_rel_destination_oid with the Value of OBJECTID.
Add another AttributeCreator to the canvas and connect it to the Structure reader feature type. In the parameters, create a new attribute called geodb_rel_origin_oid with the Value of OBJECTID.
4. Merge Features
With the primary and foreign keys set, we can now merge the features using the FeatureJoiner. This step will merge the features using the field shared by the two feature classes, in this case, Structure’s SITEID and Address’s REMARKS.
Add a FeatureJoiner to the canvas and connect the ADDRESS AttributeCreator to the Left input port and the Structure AttributeCreator_2 to the Right input port. In the parameters, set the Join On Left to REMARKS and the Right to SITEID, then click OK.
5. Set Feature Class
Lastly, another AttributeCreator transformer is required to ensure that ArcGIS recognizes the features as a feature class. You can do this by setting the geodb_type as geodb_relationship.
Add an AttributeCreator to the canvas and connect it to the Joined output port on the FeatureJoiner. In the parameters, create a new attribute called geodb_type and set the Value to geodb_relationship, then click OK.
6. Write out to File Geodatabase
Finally, we can write out to a geodatabase. Add an Esri Geodatabase (File Geodb) writer to the canvas and browse to a location to save the geodatabase. Change the Feature Class or Table Definition to Import from Database and then open the Parameters.

In the Parameters, enable Overwrite Existing Geodatabase and then for Template File Geodatabase browse to the Many2ManyTemplate.gdb dataset. Click OK twice to add the writer.
In the Import Writer Feature Types dialog, browse to the Many2ManyTemplate.gdb, then click OK.
Then in the Select Feature Types dialog, only select Structure_to_Address_rel, and click OK.
Once the Structure_to_Address_rel writer feature type appears, connect it to the AttributeCreator_3.
At this stage of the workspace, we are writing directly to the relationship table. To do this correctly, we need the values we set earlier:
geodb_rel_origin_oidgeodb_rel_destination_oidgeodb_typeWe do not have to set the Foreign Key values (StructureEventID and AddressEventID) because the writer will populate these if we mapped the above values correctly.
7. Save and Run the Workspace
Save and then run the workspace. The Relationship class should now be populated with the Foreign key values for AddressEventID and StructureEventId. View your output in ArcGIS.
In the M:N example above, the data already existed, and we were populating the relationship table to create the relation between the addresses and structures.
If you want to insert the data into a new geodatabase with a relationship class, you require a combination of the 1:M relationship workspace and updating a M:N relationship workspace. Again, you need to use ArcGIS to create the relationship class in the destination geodatabase (or geodatabase template) before translation. You can view an example of such a workspace in the Many2ManyAdvanced template (see the Resources section above).