diff --git a/src/Pool.php b/src/Pool.php index 4f03e21..d671fed 100644 --- a/src/Pool.php +++ b/src/Pool.php @@ -437,6 +437,10 @@ public function getGeneratedTypeFields(string $type): array return $this->types[$this->requireRegisteredType($type)]['generated_fields']; } + public function getTypeSqlReadStatements(string $type): array + { + return $this->types[$this->requireRegisteredType($type)]['sql_read_statements']; + } public function getTypeProperty(string $type, string $property, callable $callback): mixed { $registered_type = $this->requireRegisteredType($type); @@ -456,7 +460,7 @@ private function getSelectOneByType(string $type): string if (empty($this->types[$type]['sql_select_by_ids'])) { $this->types[$type]['sql_select_by_ids'] = sprintf( 'SELECT %s FROM %s WHERE `id` IN ? ORDER BY `id`', - $this->getEscapedTypeFields($type), + $this->getTypeFieldsReadStatement($type), $this->getTypeTable($type, true) ); } @@ -491,21 +495,21 @@ public function getTypeFieldsReadStatement(string $type): string { return $this->getTypeProperty( $type, - 'escaped_fields', + 'field_read_statements', function () use ($type) { $table_name = $this->getTypeTable($type, true); - $escaped_field_names = []; + $field_read_statements = []; - foreach ($this->getTypeFields($type) as $field_name) { - $escaped_field_names[] = $table_name . '.' . $this->connection->escapeFieldName($field_name); + foreach ($this->getTypeSqlReadStatements($type) as $sql_read_statement) { + $field_read_statements[] = $sql_read_statement; } foreach ($this->getGeneratedTypeFields($type) as $field_name) { - $escaped_field_names[] = $table_name . '.' . $this->connection->escapeFieldName($field_name); + $field_read_statements[] = $table_name . '.' . $this->connection->escapeFieldName($field_name); } - return implode(',', $escaped_field_names); + return implode(',', $field_read_statements); } ); } @@ -671,6 +675,7 @@ public function registerType(string ...$types): PoolInterface 'table_name' => $default_properties['table_name'], 'fields' => $default_properties['entity_fields'], 'generated_fields' => $default_properties['generated_entity_fields'], + 'sql_read_statements' => $default_properties['sql_read_statements'], 'order_by' => $default_properties['order_by'], ]; } diff --git a/test/src/GeneratedFieldsTest.php b/test/src/GeneratedFieldsTest.php index 43384a3..2e1fdaa 100644 --- a/test/src/GeneratedFieldsTest.php +++ b/test/src/GeneratedFieldsTest.php @@ -117,6 +117,10 @@ public function testPoolIncludesGeneratedFieldsInTypeFieldsList() $escaped_type_fields = $this->pool->getEscapedTypeFields(StatsSnapshot::class); $this->assertIsString($escaped_type_fields); $this->assertStringContainsString('is_used_on_day', $escaped_type_fields); + + $type_fields_read_statement = $this->pool->getTypeFieldsReadStatement(StatsSnapshot::class); + $this->assertIsString($type_fields_read_statement); + $this->assertStringContainsString('is_used_on_day', $type_fields_read_statement); } public function testGeneratedFieldsAreHydrated()