How do I relate models? (Part Two)

Once you’ve learned how to relate models, you may want to add additional data to the relationship – where the two models are joined.

For example, you may want to document the role a person played in an organization. This information does not belong to either the organization or the person model, as it describes a person’s relationship to the organization.

To add a field for this data, go back to Project Settings, the Organization model, and the Relationships tab. Edit the Person model that is related to this organization.

Switch to the Fields tab.

Add a Data Type and name it. In the case of roles at an organization, you may want a String that will let you add any short description. If there’s a set list of possible roles, Select may be more appropriate to control the list of options.

By default, this field is optional; selecting the Required box will make a role required for every person who is added to this organization. Selecting “Searchable” will make this field searchable in Core Data. The Order number must be at least 1.

Once you Save the new field that you’ve added, you’ll have to Save the Relationship and the Model.

To verify that your model was updated, switch to Data Entry mode and go to the Organization model. When you add or edit a person, you’ll be asked for their Role.

If you go to the person’s record, you’ll still see the related organization.

If you click “Edit” on the saved organization, the Role that you entered will appear.