Skip to content

Commit c5510fb

Browse files
committed
Fixed model generation with same names
1 parent e9bdb31 commit c5510fb

File tree

2 files changed

+28
-9
lines changed

2 files changed

+28
-9
lines changed

src/com/magento/idea/magento2plugin/actions/generation/dialog/NewModelsDialog.java

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -223,14 +223,22 @@ private void onOK() {
223223
private PsiFile generateModelFile() {
224224
final NamespaceBuilder modelNamespace = getModelNamespace();
225225
final NamespaceBuilder resourceModelNamespace = getResourceModelNamespace();
226+
String resourceModelFqn = resourceModelNamespace.getClassFqn();
227+
String resorceModelName = getResourceModelName();
228+
229+
if (getModelName().equals(getResourceModelName())) {
230+
resourceModelFqn += " as ResourceModel";
231+
resorceModelName = "ResourceModel";
232+
}
233+
226234
return new ModuleModelGenerator(new ModelData(
227235
getModuleName(),
228236
getDbTableName(),
229237
getModelName(),
230-
getResourceModelName(),
238+
resorceModelName,
231239
modelNamespace.getClassFqn(),
232240
modelNamespace.getNamespace(),
233-
resourceModelNamespace.getClassFqn()
241+
resourceModelFqn
234242
), project).generate(NewModelsDialog.ACTION_NAME, true);
235243
}
236244

@@ -250,17 +258,30 @@ private PsiFile generateCollectionFile() {
250258
final NamespaceBuilder resourceModelNamespace = getResourceModelNamespace();
251259
final NamespaceBuilder modelNamespace = getModelNamespace();
252260
final NamespaceBuilder collectionNamespace = getCollectionNamespace();
261+
String modelFqn = modelNamespace.getClassFqn();
262+
String modelName = getModelName();
263+
String resourceModelFqn = resourceModelNamespace.getClassFqn();
264+
String resorceModelName = getResourceModelName();
265+
266+
267+
if (getModelName().equals(getResourceModelName())) {
268+
modelFqn += " as Model";
269+
modelName = "Model";
270+
resourceModelFqn += " as ResourceModel";
271+
resorceModelName = "ResourceModel";
272+
}
273+
253274
return new ModuleCollectionGenerator(new CollectionData(
254275
getModuleName(),
255276
getDbTableName(),
256-
getModelName(),
277+
modelName,
257278
getCollectionName(),
258279
collectionNamespace.getClassFqn(),
259280
getCollectionDirectory(),
260281
collectionNamespace.getNamespace(),
261-
getResourceModelName(),
262-
resourceModelNamespace.getClassFqn(),
263-
modelNamespace.getClassFqn()
282+
resorceModelName,
283+
resourceModelFqn,
284+
modelFqn
264285
), project).generate(NewModelsDialog.ACTION_NAME, true);
265286
}
266287

src/com/magento/idea/magento2plugin/actions/generation/generator/ModuleModelGenerator.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -150,9 +150,7 @@ protected void fillAttributes(final Properties attributes) {
150150
attributes.setProperty("NAMESPACE", modelData.getNamespace());
151151

152152
attributes.setProperty("DB_NAME", modelData.getDbTableName());
153-
attributes.setProperty("RESOURCE_MODEL", PhpClassGeneratorUtil.getNameFromFqn(
154-
modelData.getResourceModelFqn())
155-
);
153+
attributes.setProperty("RESOURCE_MODEL", modelData.getResourceName());
156154
final List<String> uses = getUses();
157155

158156
attributes.setProperty(

0 commit comments

Comments
 (0)