Skip to content

Conversation

@wpjscc
Copy link
Contributor

@wpjscc wpjscc commented Jul 10, 2025

For example, if a user has two payment orders, only one payment order will be counted when there is a limit. Now, the limit is removed, but we can still restrict it by setting limit: 1 in the conditions.

user_orders_real_amount:
      label: real_amount
      relations: user_orders
      limit: 1
      select: 'sum(real_amount)'
user_orders_max_id:
      label: user_orders_max_id
      relations: user_orders
      limit: 1
      select: 'user_orders.id'
      conditions:  order by  user_orders.id desc limit 1

@LukeTowers
Copy link
Member

@wpjscc I don't understand the reason for this PR, why are you removing the feature?

@LukeTowers LukeTowers added the needs response Issues/PRs where a maintainer is awaiting a response from the submitter label Jul 16, 2025
@wpjscc
Copy link
Contributor Author

wpjscc commented Jul 17, 2025

for example

Model: User
table: users

id name
1 John

User hasMany

public $hasMany=['user_orders' => [UserOrder::class ]];

Model: UserOrder
table: user_orders

id user_id real_amount
1 1 50.00
2 1 50.00
user_orders_real_amount:
      label: real_amount
      relations: user_orders
      limit: 1
      select: 'sum(real_amount)'

generate sql is

(select sum(real_amount) from user_orders where users.id =  user_orders.user_id limit 1) as user_orders_real_amount

the user_orders_real_amount result is 50,it should is 100

the PR generate sql is

(select sum(real_amount) from user_orders where users.id =  user_orders.user_id) as user_orders_real_amount

it result is 100

@LukeTowers
Copy link
Member

@wpjscc Yes, but why are you even setting a limit value if you don't want your query limited? That's the part that I don't understand, you don't need to remove the feature for everyone when you can just remove that line from your YAML.

@wpjscc
Copy link
Contributor Author

wpjscc commented Jul 18, 2025

if do not have limit : 1

it will generate sql

(select group_concat(sum(real_amount) separator ', ') from user_orders where users.id =  user_orders.user_id) as user_orders_real_amount

There is a contradiction. If we use relations, then we must use limit:1 to call DbDongle::raw($sqlSelect). In this case, the order result is 50, but we expect it to be 100

So how can we generate such SQL when using relations

(select sum(real_amount) from user_orders where users.id =  user_orders.user_id) as user_orders_real_amount

rather than

(select group_concat(sum(real_amount) separator ', ') from user_orders where users.id =  user_orders.user_id) as user_orders_real_amount

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs response Issues/PRs where a maintainer is awaiting a response from the submitter

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants