Skip to content

Conversation

@bishwajitcadhikary
Copy link
Contributor

This pull request introduces support for generating average aggregates for Eloquent relationships in the output, along with a new WriteAvg action and comprehensive tests.

Key changes:

  • Added support for averages in JSON and TypeScript output generation.
  • Introduced configuration options: no-averages and optional-averages to control inclusion and optionality of averages.
  • Updated CLI and model builder logic to handle averages similarly to sums.
  • Implemented the WriteAvg action for outputting averages.
  • Added comprehensive tests for the WriteAvg action, covering:
    • String and array output
    • Indentation
    • Optional averages
    • Different case styles (snake, pascal, camel)
  • Updated documentation and examples to reflect the new averages feature.

This enhancement provides more flexibility and completeness in model type generation, especially for projects that require average aggregates on relationships.

@tcampbPPU tcampbPPU requested a review from Copilot July 9, 2025 20:45
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds comprehensive support for generating average aggregates on Eloquent relationships in TypeScript model definitions. The implementation mirrors the existing sums functionality and provides flexible configuration options for controlling how averages are included in the generated output.

Key changes:

  • Introduced WriteAvg action for generating average aggregate TypeScript definitions
  • Added CLI options --no-averages and --optional-averages for controlling average inclusion and optionality
  • Extended all relevant generator classes to handle averages alongside existing sums, counts, and exists functionality

Reviewed Changes

Copilot reviewed 9 out of 10 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
test/Tests/Feature/Actions/WriteAvgTest.php Comprehensive test suite for the new WriteAvg action covering various output formats and case styles
src/Actions/WriteAvg.php Core action class that generates TypeScript definitions for average aggregates
src/Commands/ModelTyperCommand.php Added CLI options for controlling averages generation
src/Actions/Generator.php Extended main generator to accept and pass through averages parameters
src/Actions/GenerateJsonOutput.php Added averages support to JSON output generation
src/Actions/GenerateCliOutput.php Added averages support to CLI/TypeScript output generation
src/Actions/BuildModelDetails.php Extended model builder to extract averages from Laravel models
config/modeltyper.php Added configuration options for averages functionality
readme.md Updated documentation to include averages feature usage examples

Comment on lines +63 to +68
$sums = collect($laravelModel->sums ?? [])->map(fn ($relation, $column) => [
'relation' => $relation,
'column' => $column,
])->values();

$averages = collect($laravelModel->averages ?? [])->map(fn ($relation, $column) => [
Copy link

Copilot AI Jul 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The parameter order in the map callback is incorrect. It should be fn ($column, $relation) to match the documented format 'column_to_sum' => 'relationship_name', or the documentation should be updated to match this implementation.

Suggested change
$sums = collect($laravelModel->sums ?? [])->map(fn ($relation, $column) => [
'relation' => $relation,
'column' => $column,
])->values();
$averages = collect($laravelModel->averages ?? [])->map(fn ($relation, $column) => [
$sums = collect($laravelModel->sums ?? [])->map(fn ($column, $relation) => [
'relation' => $relation,
'column' => $column,
])->values();
$averages = collect($laravelModel->averages ?? [])->map(fn ($column, $relation) => [

Copilot uses AI. Check for mistakes.
'column' => $column,
])->values();

$averages = collect($laravelModel->averages ?? [])->map(fn ($relation, $column) => [
Copy link

Copilot AI Jul 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The parameter order in the map callback is incorrect. It should be fn ($column, $relation) to match the documented format 'column_to_average' => 'relationship_name'.

Suggested change
$averages = collect($laravelModel->averages ?? [])->map(fn ($relation, $column) => [
$averages = collect($laravelModel->averages ?? [])->map(fn ($column, $relation) => [

Copilot uses AI. Check for mistakes.
Comment on lines 225 to 226
];
```
Copy link

Copilot AI Jul 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This closing bracket appears to be orphaned and doesn't match any opening bracket in the averages section, creating invalid PHP syntax in the documentation example.

Suggested change
];
```

Copilot uses AI. Check for mistakes.
@github-actions
Copy link

github-actions bot commented Aug 9, 2025

This PR is stale because it has been open 45 days with no activity. Remove stale label or comment or this will be closed in 10 days.

@github-actions github-actions bot added the Stale label Aug 9, 2025
@github-actions github-actions bot removed the Stale label Sep 28, 2025
@github-actions
Copy link

This PR is stale because it has been open 45 days with no activity. Remove stale label or comment or this will be closed in 10 days.

@github-actions github-actions bot added the Stale label Oct 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant