Skip to content

Commit f0dd79e

Browse files
author
Bob Garner
committed
More bug fixes and added getImplicitToEntity() method on relationship.
This method will make it easier for templates to get the many-to-many entity via the implicit table added.
1 parent 6770681 commit f0dd79e

File tree

5 files changed

+48
-27
lines changed

5 files changed

+48
-27
lines changed

docs/emc/EMC_entity.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1226,6 +1226,12 @@ Returns the "from" part of the relationship which references the entity in which
12261226

12271227
<hr/>
12281228

1229+
#### `MTEntity` **`implicitToEntity`**
1230+
1231+
Gets the entity on the other side of an implicit many-to-many entity.
1232+
1233+
<hr/>
1234+
12291235
#### `boolean` **`isImplicit`**
12301236

12311237
Indicates whether the relationship was created because although it was not declared it can be implied based on relationships declared to this entity.

docs/etl/ETL.md

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -128,9 +128,9 @@ Here is the full list of filters:
128128
| [`lowercase`](#filter_detail_lowercase) | Forces all characters of the input to be lowercase. |
129129
| [`map`](#filter_detail_map) | This filter is probably the most complicated one but can be very powerful in helping to pattern match an expression at its input with one provided as a parameter. When the expressions match, it not only returns true but also maps operands from the input expression to the parameter expression. |
130130
| [`name`](#filter_detail_name) | This simply calls `getName()` on the input. It is more of a convenient way to get the name by using a filter. |
131+
| [`nameas`](#filter_detail_nameas) | Places underscore between words then forces all characters to be lowercase. |
131132
| [`path`](#filter_detail_path) | This will convert a string or namespace object into a string where by a '/' character is used as a delimiter instead of a '.'. This is useful when you need to convert a namespace into a filepath. |
132133
| [`plural`](#filter_detail_plural) | This will attempt to pluralize the last word of the input string. If it can't determine the pluralization it may just return the same string. |
133-
| [`rename`](#filter_detail_rename) | Places underscore between words then forces all characters to be lowercase. |
134134
| [`reverse`](#filter_detail_reverse) | Given a collection of objects, this will return a collection that has the reverse order of the input. |
135135
| [`sort`](#filter_detail_sort) | Given a collection of objects, this will return a collection that is sorted by name. This is useful when generating code that is consistent each time in terms of the order of objects in the output. |
136136
| [`title`](#filter_detail_title) | Given a string of words in camel case format, this will capitalize each word in the string except those words that are typically not capitalized in a title (such as 'of', 'the'. 'and', etc.). |
@@ -417,49 +417,49 @@ Valid inputs for this filter are:
417417

418418
<hr/>
419419

420-
<a name="filter_detail_path"></a>
421-
##### Filter: `path`
420+
<a name="filter_detail_nameas"></a>
421+
##### Filter: `nameas`
422422

423-
This will convert a string or namespace object into a string where by a '/' character is used as a delimiter instead of a '.'. This is useful when you need to convert a namespace into a filepath.
423+
Places underscore between words then forces all characters to be lowercase.
424424

425425
Valid inputs for this filter are:
426426

427427
| Class of Valid Input | Description |
428428
|---|---|
429-
| `String` | The string that represents a period-delimited namespace (for instance: com.example.something). |
430-
| `MTNamespace` | A namespace object that is obtained from an object in your model. |
429+
| `String` | The string to change into an underscore lowercase format. |
430+
431+
This filter has the following parameters:
432+
433+
| Usage with Parameter | Description |
434+
|---|---|
435+
| `nameas:`*method* | Specifies the naming method: standard, underscore, underscoreLowercase, underscoreUppercase, lowercase, uppercase, capitalize, dashesLowercase, dashesUppercase, parentPrefix |
431436

432437
<hr/>
433438

434-
<a name="filter_detail_plural"></a>
435-
##### Filter: `plural`
439+
<a name="filter_detail_path"></a>
440+
##### Filter: `path`
436441

437-
This will attempt to pluralize the last word of the input string. If it can't determine the pluralization it may just return the same string.
442+
This will convert a string or namespace object into a string where by a '/' character is used as a delimiter instead of a '.'. This is useful when you need to convert a namespace into a filepath.
438443

439444
Valid inputs for this filter are:
440445

441446
| Class of Valid Input | Description |
442447
|---|---|
443-
| `String` | The string to pluralize. |
448+
| `String` | The string that represents a period-delimited namespace (for instance: com.example.something). |
449+
| `MTNamespace` | A namespace object that is obtained from an object in your model. |
444450

445451
<hr/>
446452

447-
<a name="filter_detail_rename"></a>
448-
##### Filter: `rename`
453+
<a name="filter_detail_plural"></a>
454+
##### Filter: `plural`
449455

450-
Places underscore between words then forces all characters to be lowercase.
456+
This will attempt to pluralize the last word of the input string. If it can't determine the pluralization it may just return the same string.
451457

452458
Valid inputs for this filter are:
453459

454460
| Class of Valid Input | Description |
455461
|---|---|
456-
| `String` | The string to change into an underscore lowercase format. |
457-
458-
This filter has the following parameters:
459-
460-
| Usage with Parameter | Description |
461-
|---|---|
462-
| `rename:`*method* | Specifies the renaming method: standard, underscore, underscoreLowercase, underscoreUppercase, lowercase, uppercase, capitalize, dashesLowercase, dashesUppercase, parentPrefix |
462+
| `String` | The string to pluralize. |
463463

464464
<hr/>
465465

src/main/java/org/entityc/compiler/model/domain/MTDERelationship.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,13 +99,13 @@ public void setDomainEntity(MTDEntity domainEntity) {
9999
@ModelMethod(category = ModelMethodCategory.RELATIONSHIP,
100100
description = "Indicates if this relationship is a one-to-many.")
101101
public boolean isOneToMany() {
102-
return relationship.isOneToMany();
102+
return relationship != null && relationship.isOneToMany();
103103
}
104104

105105
@ModelMethod(category = ModelMethodCategory.RELATIONSHIP,
106106
description = "Indicates if this relationship is a many-to-many.")
107107
public boolean isManyToMany() {
108-
return relationship.isManyToMany();
108+
return relationship != null && relationship.isManyToMany();
109109
}
110110

111111
@Override

src/main/java/org/entityc/compiler/model/entity/MTRelationship.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,18 @@ public boolean isManyToMany() {
201201
return getFullRelationshipPlurality() == FullRelationshipPlurality.MANY_TO_MANY;
202202
}
203203

204+
@ModelMethod(category = ModelMethodCategory.RELATIONSHIP,
205+
description =
206+
"Gets the entity on the other side of an implicit many-to-many entity.")
207+
public MTEntity getImplicitToEntity() {
208+
for(MTRelationship mmRel : to.getEntity().implicitRelationships) {
209+
if (!mmRel.to.getEntityName().equals(from.getEntityName())) {
210+
return mmRel.to.getEntity();
211+
}
212+
}
213+
return null;
214+
}
215+
204216
@Override
205217
public void accept(MTVisitor visitor) {
206218

src/main/java/org/entityc/compiler/transform/MTVImplicitTransform.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import org.entityc.compiler.model.entity.MTEnum;
1515
import org.entityc.compiler.model.entity.MTPrimaryKey;
1616
import org.entityc.compiler.model.entity.MTRelationship;
17+
import org.entityc.compiler.util.ECLog;
1718

1819
// TODO: Create index from parent relationships
1920

@@ -67,32 +68,34 @@ public void visitAttribute(MTAttribute attribute) {
6768
public void visitRelationship(MTRelationship relationship) {
6869

6970
MTEntity fromEntity = relationship.getFrom().getEntity();
70-
MTEntity toEntity = relationship.getTo().getEntity();
71+
MTEntity toEntity = relationship.getTo().getEntity();
7172
if (toEntity == null || fromEntity == null) {
7273
relationship.resolveReferences(root.getSpace(), 0);
7374
toEntity = relationship.getTo().getEntity();
7475
fromEntity = relationship.getFrom().getEntity();
76+
if (toEntity == null) {
77+
ECLog.logFatal("The entity \"" + fromEntity.getName() + "\" has a relationship \"" + relationship.getName() + "\" but not to anything.");
78+
}
7579
}
7680
MTPrimaryKey toPrimaryKey = toEntity.getPrimaryKey();
7781
if (toPrimaryKey == null) {
7882
return;
7983
}
80-
FullRelationshipPlurality plurality = relationship.getFullRelationshipPlurality();
81-
MTPrimaryKey fromPrimaryKey = fromEntity.getPrimaryKey();
84+
FullRelationshipPlurality plurality = relationship.getFullRelationshipPlurality();
85+
MTPrimaryKey fromPrimaryKey = fromEntity.getPrimaryKey();
8286
if (!relationship.getFrom().getEntity().isImplicit()) {
8387
if (fromPrimaryKey == null && plurality != FullRelationshipPlurality.MANY_TO_ONE) {
8488
return;
8589
}
8690
}
8791
if (toPrimaryKey.getAttributes().size() != 1
88-
|| (fromPrimaryKey != null && fromPrimaryKey.getAttributes().size() != 1)) {
92+
|| (fromPrimaryKey != null && fromPrimaryKey.getAttributes().size() != 1)) {
8993
return; // unsupported right now
9094
}
9195

9296
switch (plurality) {
9397
case MANY_TO_MANY: {
9498
// create table to support relationship
95-
String virtualEntityName = fromEntity.getName() + "-" + toEntity.getName();
9699
MTEntity.AddImplicitManyToManyEntity(fromEntity.getSpace(), fromEntity, toEntity);
97100
}
98101
break;

0 commit comments

Comments
 (0)