Inconsistencies in Builder::addSelect #54167
Unanswered
liamduckett
asked this question in
Ideas
Replies: 1 comment
-
Hey @liamduckett , I came accross same issue last night and I found out a workaround. When we are using $two = User::query()
->addSelect([
'power' => function ($query) {
$query->selectRaw("SUM(items.power))
->from('items')
->whereColumn('items.user_id', 'users.id')
->limit(1);
}
]); Now a |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Laravel Version
11.36.1
PHP Version
8.4
Database Driver & Version
No response
Description
Hey, I'd usually try a PR for this sort of thing - I felt it better to ask for some guidance on this one first.
I'm using SQLite, although I don't think this is too relevant here.
I'd expect these two queries to result in the same raw SQL. Yet:
The first one adds selects all users columns, whilst the second one discards them. I want to say I'd expect the former (as I'd assume addSelect doesn't discard existing selected columns, and without specifying it, all user columns would be selected?).
This happens because of:
My questions:
$this->select($this->from.'.*');
out of the isQueryable check? Appreciate this would be a breaking change (in quite a key part of the framework!), and would need to be handled accordingly.May be worth noting the following cases:
Which result in the same result as
$two
. Appreciate these may be more involved to change (if desired) - so currently plan to handle them afterwards.Steps To Reproduce
Repeat of above:
I'd expect these two queries to result in the same raw SQL. Yet:
Beta Was this translation helpful? Give feedback.
All reactions