FamilySearch/gedcomx-php-sample-app

Load persons with relationships?

Opened this issue · 2 comments

From @jimmyz:

For the Read Family, the code is currently using loadParentRelationships, loadSpouseRelationships, and loadChildRelationships.

You may consider using readParents, readSpouses, and readChildren methods. These should provide the relationships and the person objects in one call.

The loadParentRelationships method uses the "Relationships to Parents" REST resource, which only contains relationship data. https://familysearch.org/developers/docs/api/tree/Relationships_to_Parents_resource

The readParents method uses the "Parents of a Person" REST resource, which contains the parent person objects and the relationship https://familysearch.org/developers/docs/api/tree/Read_Parents_of_a_Person_usecase

I updated the Read Family example to use the different endpoints which returns the persons. In the commit you'll notice that the example is much more complex now.

The endpoints don't return all persons in the relationships, just the particular type that was requested.

  • readParents only returns the parents, not the primary person (which is always the child).
  • readSpouses only returns the spouses, not the primary person.
  • readChildren only returns the children, not the parents. One of the parents is the primary person, the other parent may or may not be a spouse. I left a comment in the code discussing this.

The new states returned by readParents, readSpouses, and readChildren did not make it easy to assemble the resulting relationships. It would have been easier if they all had a getPerson() method. I opened an issue on the SDK about this.

Processing these relationships, as currently shown in the example, is painful. There must be a better way. Given the async nature of PHP, I would rather request all the relationships without the persons then request the persons one at a time as I needed them even though that would be slower.

In a case like this where we're processing all relationships, using the Persons with Relationships resource would be much easier.

I agree that the example is now much more complex. However, it is a common use case. We should provide an alternative implementation using Persons with Relationships. It will be interesting to see how things play out in code and performance.

My thought is that we should use the example to improve the SDK functionality, much like you've already suggested with the getPerson() method issue.

My goal is for the SDK to provide an interface that allows the common use cases to be handled in an elegant way. I think it is moving that direction.