* @param value GenericValue instance containing the entity
* @return GenericPK containing a possibly incomplete PrimaryKey object representing the related entity or entities
*/
public GenericPK getRelatedDummyPK(String relationName, Map<String, ? extends Object> byAndFields, GenericValue value) throws GenericEntityException {
ModelEntity modelEntity = value.getModelEntity();
ModelRelation relation = modelEntity.getRelation(relationName);
if (relation == null) {
throw new GenericModelException("Could not find relation for relationName: " + relationName + " for value " + value);
}
ModelEntity relatedEntity = getModelReader().getModelEntity(relation.getRelEntityName());
// put the byAndFields (if not null) into the hash map first,
// they will be overridden by value's fields if over-specified this is important for security and cleanliness
Map<String, Object> fields = FastMap.newInstance();
if (byAndFields != null) fields.putAll(byAndFields);
for (int i = 0; i < relation.getKeyMapsSize(); i++) {
ModelKeyMap keyMap = relation.getKeyMap(i);
fields.put(keyMap.getRelFieldName(), value.get(keyMap.getFieldName()));
}
GenericPK dummyPK = GenericPK.create(relatedEntity, fields);
dummyPK.setDelegator(this);