Skip to content

Commit da10ff0

Browse files
Resolve the relationships on persist of fabricated sobjects
1 parent cd5e5b8 commit da10ff0

File tree

2 files changed

+21
-7
lines changed

2 files changed

+21
-7
lines changed

framework/default/sobject-fabricator-extensions/classes/ortoo_FabricatedSObjectRegister.cls

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ public class ortoo_FabricatedSObjectRegister {
4545

4646
sobjectsByFabricated.put( thisFabricatedObject, objectToStore );
4747
}
48-
system.debug( sobjectsByFabricated.values() );
4948

5049
// work out the order to do things in, using the directed graph
5150
List<Object> childToParentTypes = graph.generateSorted();
@@ -102,21 +101,19 @@ public class ortoo_FabricatedSObjectRegister {
102101
Sobject parentSobject = sobjectsByFabricated.get( parent );
103102
Sobject childSobject = sobjectsByFabricated.get( child );
104103

105-
system.debug( 'registering the relationship: ' + childSobject + ' : ' + relationship + ' : ' + parentSobject );
106-
107104
uow.registerRelationship( childSobject, relationship, parentSobject );
108105
}
109106
}
110107

111108
public static Relationship buildChildOfRelationship( sfab_FabricatedSObject child, String relationship, sfab_FabricatedSObject parent )
112109
{
113-
// TODO: resolve the passed in relationship
114-
return new Relationship( child, Contact.AccountId, parent );
110+
SobjectField relationshipField = new sfab_ObjectDescriber().getFieldForParentRelationship( child.getSobjectName(), relationship );
111+
return new Relationship( child, relationshipField, parent );
115112
}
116113

117114
public static Relationship buildParentOfRelationship( sfab_FabricatedSObject parent, String relationship, sfab_FabricatedSObject child )
118115
{
119-
// TODO: resolve the passed in relationship
120-
return new Relationship( child, Contact.AccountId, parent );
116+
SobjectField relationshipField = new sfab_ObjectDescriber().getFieldForChildRelationship( parent.getSobjectName(), relationship );
117+
return new Relationship( child, relationshipField, parent );
121118
}
122119
}

framework/default/sobject-fabricator/classes/sfab_ObjectDescriber.cls

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,16 @@ public with sharing class sfab_ObjectDescriber {
1010
return getObjectDescriber( objectName )?.getField( fieldName );
1111
}
1212

13+
public SObjectField getFieldForChildRelationship( String objectName, String relationshipName ) {
14+
ensureSingleObjectDescriberIsInitialised( objectName );
15+
return getObjectDescriber( objectName )?.getChildRelationshipNamed( relationshipName )?.getField();
16+
}
17+
18+
public SObjectField getFieldForParentRelationship( String objectName, String relationshipName ) {
19+
ensureSingleObjectDescriberIsInitialised( objectName );
20+
return getObjectDescriber( objectName )?.getParentRelationshipNamed( relationshipName )?.getField();
21+
}
22+
1323
public Boolean objectHasSimpleFieldNamed( String objectName, String fieldName ) {
1424
ensureSingleObjectDescriberIsInitialised( objectName );
1525
return getObjectDescriber( objectName )?.hasSimpleFieldNamed( fieldName );
@@ -235,6 +245,10 @@ public with sharing class sfab_ObjectDescriber {
235245
return fieldDescribe.getName();
236246
}
237247

248+
public SobjectField getField() {
249+
return fieldDescribe.getSobjectField();
250+
}
251+
238252
public List<String> getTargetObjectTypes() {
239253

240254
if ( !isValid() ) {
@@ -295,6 +309,9 @@ public with sharing class sfab_ObjectDescriber {
295309
return String.valueOf( schemaRelationship.getChildSObject() );
296310
}
297311

312+
public SobjectField getField() {
313+
return schemaRelationship.getField();
314+
}
298315
// Some don't have names - and if they don't have names they can't possibly be
299316
// set by the fabricator, so must be invalid.
300317
public Boolean isValid() {

0 commit comments

Comments
 (0)