Previous | Next
WireHose Developers Guide

Multiple affiliate best practices

The best way to handle multiple affiliates in your code is to not make any assumptions about whether or not subentities are available. This section provides some techniques you should follow in your own code.

Modeling entities

To model an entity which may become the parent of affiliate-based subentities, set the entity so it is not abstract and does not have a restricting qualifier on the affiliate property. WireHose will add the appropriate restricting qualifier to the parent entity when creating the first subentity.

Creating objects

WHEnterpriseObject provides the createAndInsertInstance(EOEditingContext, String entityName, String affiliateName) utility method, which functions similarly to the one defined in EOUtilities. The WireHose version provides an additional parameter, affiliateName, which is used to specify the affiliate the newly created instance should belong to.

If there is an affiliate-based subentity available for the specified entity, then the returned object will be of that entity, otherwise it will be of the specified entity. In either case, the affiliate property will be set on the newly created object if the entity has a class property named "affiliate".

Fetching objects

If you are fetching objects which belong to a specific affiliate, check for the existence of an affiliate-based subentity like this:

EOEditingContext ec; // assume exists
EOFetchSpecification fetchSpec; // assume exists
String affiliateName = "MyAffiliate";
String entityName = "SomeEntity";
String entityToFetch = WHEnterpriseObject.subEntityNameForAffiliate(entityName, affiliateName);
if (EOUtilities.modelGroup(ec).entityNamed(entityToFetch) == null) {
	entityToFetch = entityName;
NSArray objs = ec.objectsWithFetchSpecification(fetchSpec);

Previous | Next