Versions Compared


  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migrated to Confluence 5.3


Code Block

Add convenience methods onto your Person class (optional, but handy):

Code Block
public ERTaggableERTaggable<Person> taggable() {
	return ERTaggable.taggable(this);

public static ERTaggableEntityERTaggableEntity<Person> taggableEntity() {
	return new ERTaggableEntity.taggableEntity(Person.ENTITY_NAME);

Tag like the wind:

Code Block
Person mike = Person.createPerson(editingContext, "Mike Schrag");
ERTaggable taggableMike = mike.taggable();
taggableMike.addTags("mike employee important");

NSArray matchingPeople = Person.taggableEntity().fetchTaggedWith("employee", editingContext);
NSDictionary<EOEntity, NSArray<? extends ERXGenericRecord>> matchingItems = ERTaggableEntity.fetchAllTaggedWith("mike", editingContext);


By default all entities share the same corpus of tag names. For any entity, you can register a custom ERTag subclass that stores in a separate table instead. This is generally only an issue if you need to provide tag completion and you want to restrict the set of completion offerings. Note that hooking to a custom ERTag table also requires that you use the optional constructor on the migration superclass to specify the name of that entity.

By default, tags are normalized by trimming and lowercasing them. You can override the tag normalizer that is used by setting it on your ERTaggableEntity. An example implementation is

Code Block

public class TagNormalizer implements ERTagNormalizer {
  public String normalize(String tag) {

    String normalizedTag = tag;
    if (normalizedTag != null) {
      normalizedTag = normalizedTag.trim();
    return normalizedTag;

You can then register that normalizer wherever you have an instance method such as

Code Block

taggableMike = mike.taggable();
TagNormalizer myNormalizer = new TagNormalizer();

You MUST register your taggable entities prior to attempting any tagging operations. The framework will throw an exception scolding you if you do not.
By default, your EOModels are modified on-the-fly to inject tagging support into them. If you don't like magic, you can instead manually create the join entity between your entity and the ERTag entity. You MUST also create a flattened to-many relationship from your entity to the ERTag table through your join entity. If you name that relationship anything other than "tags" (or you use a custom ERTag entity), you must specify the relationship name when you register the entity.
Tags are unique and shared. To ensure this, ERTag commits new tag names in a separate transaction. This can lead to a potentially undesirable (yet mostly harmless) side effect where new tag names may be committed even though you roll back your editing context. Only tag names have this behavior, not tag relationships on your entities.unmigrated-wiki-markup

If you don't want to use the migration, you need to create a join table that contains a "your entity id" (named item_\[WONDER:your pk column name\] for each pk attribute) and an ERTagID foreign key (named tag_id). You can name the columns whatever you want if you also manually create the join entity in your EOModel.