File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -261,6 +261,18 @@ public function getModelFields(): array
261261 return $ fields ;
262262 }
263263
264+ /**
265+ * Comprueba si el modelo contiene la columna indicada.
266+ *
267+ * @param string $columnName
268+ * @return bool
269+ */
270+ public function hasColumn (string $ columnName ): bool
271+ {
272+ $ fields = $ this ->getModelFields ();
273+ return isset ($ fields [$ columnName ]);
274+ }
275+
264276 /**
265277 * Carga un registro del modelo utilizando el código de la clave primaria del master model.
266278 *
Original file line number Diff line number Diff line change @@ -170,4 +170,14 @@ public function testIdReturnsProductId(): void
170170 // eliminamos
171171 $ this ->assertTrue ($ product ->delete ());
172172 }
173+
174+ public function testHasColumn (): void
175+ {
176+ $ variant = new VarianteProducto ();
177+
178+ $ this ->assertTrue ($ variant ->hasColumn ('referencia ' ));
179+ $ this ->assertTrue ($ variant ->hasColumn ('precio_iva ' ));
180+ $ this ->assertFalse ($ variant ->hasColumn ('columna_inexistente ' ));
181+ $ this ->assertFalse ($ variant ->hasColumn ('' ));
182+ }
173183}
You can’t perform that action at this time.
0 commit comments