@@ -50,58 +50,43 @@ class {{ name }}Table extends Table{{ fileBuilder.classBuilder.implements ? ' im
5050{%- if displayField %}
5151 $this->setDisplayField({{ (displayField is iterable ? Bake.exportArray (displayField ) : Bake.exportVar (displayField ))| raw }});
5252{% endif %}
53-
54- {%- if primaryKey %}
55- {%- if primaryKey is iterable and primaryKey | length > 1 %}
53+ {% if primaryKey %}
54+ {%~ if primaryKey is iterable and primaryKey | length > 1 %}
5655 $this->setPrimaryKey({{ Bake.exportArray (primaryKey )| raw }});
57- {{- " \n" }}
58- {%- else %}
56+ {%~ else %}
5957 $this->setPrimaryKey('{{ primaryKey | as_array| first }}');
60- {{- " \n" }}
61- {%- endif %}
58+ {%~ endif %}
6259{% endif %}
60+ {% if enums %}
6361
64- {%- if enums %}
65-
66- {% endif %}
67-
68- {%- if enums %}
69-
70- {%- for name , className in enums %}
62+ {%~ for name , className in enums %}
7163 $this->getSchema()->setColumnType('{{ name }}', \Cake\Database\Type\EnumType::from(\{{ className }}::class));
72- {% endfor %}
64+ {%~ endfor %}
7365{% endif %}
66+ {% if behaviors %}
7467
75- {%- if behaviors %}
76-
77- {% endif %}
78-
79- {%- for behavior , behaviorData in behaviors %}
68+ {%~ for behavior , behaviorData in behaviors %}
8069 $this->addBehavior('{{ behavior }}'{{ (behaviorData ? (" , " ~ Bake.exportArray (behaviorData , 2 )| raw ~ ' ' ) : ' ' )| raw }});
81- {% endfor %}
82-
83- {%- if associations .belongsTo or associations .hasMany or associations .belongsToMany %}
84-
70+ {%~ endfor %}
8571{% endif %}
86-
87- {%- for type , assocs in associations %}
88- {%- for assoc in assocs %}
89- {%- set assocData = [] %}
90- {%- for key , val in assoc %}
91- {%- if key is not same as (' alias' ) %}
92- {%- set assocData = assocData | merge ({(key ): val }) %}
93- {%- endif %}
94- {%- endfor %}
72+ {% if associations .belongsTo or associations .hasMany or associations .belongsToMany %}
73+
74+ {%~ for type , assocs in associations %}
75+ {%~ for assoc in assocs %}
76+ {%~ set assocData = [] %}
77+ {%~ for key , val in assoc %}
78+ {%~ if key is not same as (' alias' ) %}
79+ {%~ set assocData = assocData | merge ({(key ): val }) %}
80+ {%~ endif %}
81+ {%~ endfor %}
9582 $this->{{ type }}('{{ assoc .alias }}', {{ Bake.exportArray (assocData , 2 )| raw }});
96- {{- " \n " } }
97- {%- endfor %}
98- {% endfor %}
83+ {%~ endfor % }
84+ {%~ endfor %}
85+ {% endif %}
9986 }
100- {{- " \n" }}
101-
102- {%- if validation %}
103- {% set generatedFunctions = generatedFunctions | merge ([' validationDefault' ]) %}
87+ {% if validation %}
10488
89+ {%~ set generatedFunctions = generatedFunctions | merge ([' validationDefault' ]) %}
10590 /**
10691 * Default validation rules.
10792 *
@@ -110,25 +95,24 @@ class {{ name }}Table extends Table{{ fileBuilder.classBuilder.implements ? ' im
11095 */
11196 public function validationDefault(Validator $validator): Validator
11297 {
113- {% for field , rules in validation %}
114- {% set validationMethods = Bake.getValidationMethods (field , rules ) %}
115- {% if validationMethods %}
98+ {%~ for field , rules in validation %}
99+ {%~ set validationMethods = Bake.getValidationMethods (field , rules ) %}
100+ {%~ if validationMethods %}
116101 $validator
117- {% for validationMethod in validationMethods %}
118- {% if loop .last %}
119- {% set validationMethod = validationMethod ~ ' ;' %}
120- {% endif %}
102+ {%~ for validationMethod in validationMethods %}
103+ {%~ if loop .last %}
104+ {%~ set validationMethod = validationMethod ~ ' ;' %}
105+ {%~ endif %}
121106 {{ validationMethod | raw }}
122- {% endfor %}
107+ {%~ endfor %}
123108
124- {% endif %}
125- {% endfor %}
109+ {%~ endif %}
110+ {%~ endfor %}
126111 return $validator;
127112 }
128113{% endif %}
129-
130114{%- if rulesChecker %}
131- {% set generatedFunctions = generatedFunctions | merge ([' buildRules' ]) %}
115+ {%~ set generatedFunctions = generatedFunctions | merge ([' buildRules' ]) %}
132116
133117 /**
134118 * Returns a rules checker object that will be used for validating
@@ -139,21 +123,20 @@ class {{ name }}Table extends Table{{ fileBuilder.classBuilder.implements ? ' im
139123 */
140124 public function buildRules(RulesChecker $rules): RulesChecker
141125 {
142- {% for rule in rulesChecker %}
143- {% set fields = Bake.exportArray (rule .fields ) %}
144- {% set options = ' ' %}
145- {% for optionName , optionValue in rule .options %}
146- {%~ set options = (loop .first ? ' [' : options ) ~ " '#{optionName}' => " ~ Bake.exportVar (optionValue ) ~ (loop .last ? ' ]' : ' , ' ) %}
147- {% endfor %}
126+ {%~ for rule in rulesChecker %}
127+ {%~ set fields = Bake.exportArray (rule .fields ) %}
128+ {%~ set options = ' ' %}
129+ {%~ for optionName , optionValue in rule .options %}
130+ {%~ set options = (loop .first ? ' [' : options ) ~ " '#{optionName}' => " ~ Bake.exportVar (optionValue ) ~ (loop .last ? ' ]' : ' , ' ) %}
131+ {%~ endfor %}
148132 $rules->add($rules->{{ rule .name }}({{ fields | raw }}{{ (rule .extra | default ? " , '#{rule.extra}'" : ' ' )| raw }}{{ (options ? ' , ' ~ options : ' ' )| raw }}), ['errorField' => '{{ rule .fields [0 ] }}']);
149- {% endfor %}
133+ {%~ endfor %}
150134
151135 return $rules;
152136 }
153137{% endif %}
154-
155- {%- if connection is not same as (' default' ) %}
156- {% set generatedFunctions = generatedFunctions | merge ([' defaultConnectionName' ]) %}
138+ {% if connection is not same as (' default' ) %}
139+ {%~ set generatedFunctions = generatedFunctions | merge ([' defaultConnectionName' ]) %}
157140
158141 /**
159142 * Returns the database connection name to use by default.
0 commit comments