itemFKAttribute.setPrecision(itemPrimaryKey.precision());
itemFKAttribute.setScale(itemPrimaryKey.scale());
itemFKAttribute.setAllowsNull(false);
joinEntity.addAttribute(itemFKAttribute);
EOJoin join = new EOJoin(itemFKAttribute, itemPrimaryKey);
joinToItemRelationship.addJoin(join);
}
EORelationship joinToTagRelationship = new EORelationship();
joinToTagRelationship.setName(tagEntity.name());
joinToTagRelationship.setIsMandatory(true);
joinToTagRelationship.setToMany(false);
joinToTagRelationship.setJoinSemantic(EORelationship.InnerJoin);
joinEntity.addRelationship(joinToTagRelationship);
for (EOAttribute tagPrimaryKey : tagEntity.primaryKeyAttributes()) {
EOAttribute tagFKAttribute = new EOAttribute();
tagFKAttribute.setExternalType(tagPrimaryKey.externalType());
tagFKAttribute.setValueType(tagPrimaryKey.valueType());
tagFKAttribute.setName("tag_" + tagPrimaryKey.name());
tagFKAttribute.setColumnName("tag_" + tagPrimaryKey.columnName());
tagFKAttribute.setClassName(tagPrimaryKey.className());
tagFKAttribute.setWidth(tagPrimaryKey.width());
tagFKAttribute.setPrecision(tagPrimaryKey.precision());
tagFKAttribute.setScale(tagPrimaryKey.scale());
tagFKAttribute.setAllowsNull(false);
joinEntity.addAttribute(tagFKAttribute);
joinToTagRelationship.addJoin(new EOJoin(tagFKAttribute, tagPrimaryKey));
}
joinEntity.setPrimaryKeyAttributes(joinEntity.attributes());
joinEntity.setAttributesUsedForLocking(joinEntity.attributes());
entity.model().addEntity(joinEntity);
EORelationship itemToJoinRelationship = new EORelationship();
itemToJoinRelationship.setEntity(joinToItemRelationship.destinationEntity());
itemToJoinRelationship.setName("_eofInv_" + joinToItemRelationship.entity().name() + "_" + joinToItemRelationship.name());
NSArray<EOJoin> joinToItemRelationshipJoins = joinToItemRelationship.joins();
for (int joinNum = joinToItemRelationshipJoins.count() - 1; joinNum >= 0; joinNum--) {
EOJoin join = joinToItemRelationshipJoins.objectAtIndex(joinNum);
EOJoin inverseJoin = new EOJoin(join.destinationAttribute(), join.sourceAttribute());
itemToJoinRelationship.addJoin(inverseJoin);
}
itemToJoinRelationship.setDeleteRule(1); // cascade
itemToJoinRelationship.setJoinSemantic(EORelationship.InnerJoin);
itemToJoinRelationship.setToMany(true);