Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[12.x] Fix aggregate alias when using expression #54418

Merged
merged 1 commit into from
Jan 30, 2025

Conversation

iamgergo
Copy link
Contributor

@iamgergo iamgergo commented Jan 30, 2025

Recently I discovered, when using withAggregate with a custom Expression insead of passing a column, the alias is not properly formatted.

For example:

$model->withAggregate('foo', new Expression('TIMESTAMPDIFF(SECOND, `created_at`, `updated_at`)'), 'sum')

// The generated alias:

// Before: foo_sum_t_i_m_e_s_t_a_m_p_d_i_f_f_s_e_c_o_n_d_created_at_updated_at

// After: foo_sum_timestampdiffsecond_created_at_updated_at

We could add an alias explicitly to handle this, but often it's easier to use the generated column aliases.

I targeted the master branch, because I think this could be a breaking change.

@taylorotwell taylorotwell merged commit 345e755 into laravel:master Jan 30, 2025
29 checks passed
@iamgergo iamgergo deleted the master branch January 31, 2025 07:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants