Skip to content

Commit 94e1a39

Browse files
author
rotimi
committed
Added an overridden definition of getModel() in the record & collection templates to return the exact type of model for the collection and record
1 parent c4a391b commit 94e1a39

File tree

3 files changed

+17
-0
lines changed

3 files changed

+17
-0
lines changed

src/OrmClassesGenerator.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,9 @@ protected function generateCollectionClassFile(string $tableName, string $collec
324324
'{{{NAME_SPACE}}}' => ($this->config['namespace'] === null) ? '' : "namespace {$this->config['namespace']}\\{$collectionOrModelNamePrefix};",
325325
'{{{MODEL_OR_COLLECTION_CLASS_NAME_PREFIX}}}' => $collectionOrModelNamePrefix,
326326
'{{{COLLECTION_EXTENDED}}}' => $this->config['collection_class_to_extend'],
327+
'{{{MODEL_EXTENDED}}}' => $this->config['model_class_to_extend'],
328+
'{{{RECORD_CLASS_NAME_PREFIX}}}' => $recordNamePrefix,
329+
'{{{TABLE_NAME}}}' => $tableName,
327330
];
328331

329332
return strtr($this->loadedCollectionTemplateFile, $translations);
@@ -355,7 +358,9 @@ protected function generateModelClassFile(string $tableName, string $collectionO
355358
$translations = [
356359
'{{{NAME_SPACE}}}' => ($this->config['namespace'] === null) ? '' : "namespace {$this->config['namespace']}\\{$collectionOrModelNamePrefix};",
357360
'{{{MODEL_OR_COLLECTION_CLASS_NAME_PREFIX}}}' => $collectionOrModelNamePrefix,
361+
'{{{COLLECTION_EXTENDED}}}' => $this->config['collection_class_to_extend'],
358362
'{{{MODEL_EXTENDED}}}' => $this->config['model_class_to_extend'],
363+
'{{{RECORD_EXTENDED}}}' => $this->config['record_class_to_extend'],
359364
'{{{RECORD_CLASS_NAME_PREFIX}}}' => $recordNamePrefix,
360365
'{{{CREATED_TIMESTAMP_COLUMN_NAME}}}' => ($this->config['created_timestamp_column_name'] === null || !$createdColExists) ? 'null' : "'{$this->config['created_timestamp_column_name']}'",
361366
'{{{UPDATED_TIMESTAMP_COLUMN_NAME}}}' => ($this->config['updated_timestamp_column_name'] === null || !$updatedColExists) ? 'null' : "'{$this->config['updated_timestamp_column_name']}'",
@@ -373,8 +378,12 @@ protected function generateRecordClassFile(string $tableName, string $collection
373378
$translations = [
374379
'{{{NAME_SPACE}}}' => ($this->config['namespace'] === null) ? '' : "namespace {$this->config['namespace']}\\{$collectionOrModelNamePrefix};",
375380
'{{{RECORD_CLASS_NAME_PREFIX}}}' => $recordNamePrefix,
381+
'{{{COLLECTION_EXTENDED}}}' => $this->config['collection_class_to_extend'],
382+
'{{{MODEL_EXTENDED}}}' => $this->config['model_class_to_extend'],
376383
'{{{RECORD_EXTENDED}}}' => $this->config['record_class_to_extend'],
377384
'{{{DB_COLS_AS_PHP_CLASS_PROPERTIES}}}' => $phpDocDbColNamesAsPhpClassProperties,
385+
'{{{MODEL_OR_COLLECTION_CLASS_NAME_PREFIX}}}' => $collectionOrModelNamePrefix,
386+
'{{{TABLE_NAME}}}' => $tableName,
378387
];
379388

380389
return strtr($this->loadedRecordTemplateFile, $translations);

templates/TypeRecord.php.tpl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,8 @@ declare(strict_types=1);
99
class {{{RECORD_CLASS_NAME_PREFIX}}}Record extends {{{RECORD_EXTENDED}}} {
1010

1111
//put your code here
12+
public function getModel(): {{{MODEL_OR_COLLECTION_CLASS_NAME_PREFIX}}}Model {
13+
14+
return parent::getModel();
15+
}
1216
}

templates/TypesCollection.php.tpl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,8 @@ declare(strict_types=1);
66
class {{{MODEL_OR_COLLECTION_CLASS_NAME_PREFIX}}}Collection extends {{{COLLECTION_EXTENDED}}} {
77

88
//put your code here
9+
public function getModel(): {{{MODEL_OR_COLLECTION_CLASS_NAME_PREFIX}}}Model {
10+
11+
return parent::getModel();
12+
}
913
}

0 commit comments

Comments
 (0)