kapad
kapad

Reputation: 651

Drools nested aggregation

I have the following rule in drools. What's happening is that the $expense is evaluated on a per card basis. But I want it to be evaluated on a per user basis (The $u).

rule "test":

when
    $u: User()
    $card: Card(user_id == $u.id)
    $expense: Double() from 
         accumulate (
             $transaction: Transactions(
                   card_id == $card.id,
                   transaction_date >= 'startDate',
                   transaction_date <= 'endDate'
         ),
         sum($transaction.amount)
then
    // do something with expense. 
    // but I want to the expense to be the expense for a user. not a card.
end

Upvotes: 0

Views: 331

Answers (1)

Tibor Zim&#225;nyi
Tibor Zim&#225;nyi

Reputation: 317

I think you would need a user ID field in the Transactions for this to work. In that case you cam remove the card from the rule so it will work on a user basis.

Upvotes: 1

Related Questions