diff src/Generator/Model/ModelGenerator.php @ 26:555bfaa500ac codex

Big update for view creation based on the column type.
author Luka Sitas <sitas.luka.97@gmail.com>
date Thu, 15 May 2025 21:50:38 -0400
parents 31109c61ce02
children f88d2d5dee30
line wrap: on
line diff
--- a/src/Generator/Model/ModelGenerator.php	Sun May 11 21:03:51 2025 -0400
+++ b/src/Generator/Model/ModelGenerator.php	Thu May 15 21:50:38 2025 -0400
@@ -86,17 +86,6 @@
         return str_replace(['App\\', '\\'], ['app/', '/'], $this->getModelNamespace().'/'.$this->model_name($this->getTableInput()).'.php');
     }
 
-    protected function getSnippet($snippet_name)
-    {
-        // Cache snippet contents to avoid re-reading files
-        if (! isset(self::$cached_snippets[$snippet_name])) {
-            self::$cached_snippets[$snippet_name] = $this->files->get(
-                $this->resolveStubPath("/snippets/$snippet_name.stub"));
-        }
-
-        return self::$cached_snippets[$snippet_name];
-    }
-
 		protected function gatherRelations() {
 			$relations = RelationshipNavigator::getRelations($this->getCurrentTable());
 
@@ -205,10 +194,14 @@
         $hasMany = !empty($rendered['hasMany']) ? implode("\n    ", $rendered['hasMany']) : '';
         $belongsMany = !empty($rendered['belongsToMany']) ? implode("\n    ", $rendered['belongsToMany']) : '';
 
+				// Default relations are based on the belongsTo relationship
+				$default_relations = implode(", \n",  array_map(function ($rel) {return '\'' . Str::singular($rel['table']) . '\''; }, $relations['belongsTo']));
+
         // Assign to stub placeholders
         $inserts['# {{ belongs_to_relationships }}'] = $belongs;
         $inserts['# {{ has_many_relationships }}'] = $hasMany;
         $inserts['# {{ has_many_through_relationships }}'] = $belongsMany;
+				$inserts['# {{ defaultRelationsInsertPoint }}'] = $default_relations;
 
         return $inserts;
     }