Hi guys, I’m making a game score board type of app. I have a Result table where there are four columns: Winner, Loser, WinnerScore, LoserScore. And I have a Player table where there are all player names and detailed info.
My problem is, how do I calculate each player’s aggregated statistics in the Player table with data from the Result table?
For example, in the Player table for player A I have the column TotalGamesPlayed, which needs to sum the total counts from the Winner and the Loser columns of player A in the Result table. And it needs to update itself each time the Result table gets new data. How can I make these auto-updated columns with Codeless? I’m thinking about the afterCreate event handler, but I can’t think of ways to make this work. Thanks!
I think my problem can be divided in many steps (all in codeless business logic context):
How to get the latest created object in the Result table and to get properties of it?
How to update a property by adding 1? I need a way to get the original data and then add 1, for example, a new result is submitted, then in the player table, both the winner and the loser will get 1 one game in the TotalGamesPlayed column.
I looked at the data structure in the application, the applicationId of which you provided, but I did not see what you described in the topic.
It is rather difficult to answer, since it is not yet clear to me what you want to get in the end.
You can create approximately the following structure, described below, and then you will be able to determine how many games the player has played by the number of referenced objects, without resorting to additional manipulations.
Hi @Volodymyr_Ialovyi I’m using these blocks as you suggested to updated three columns in the League table, it looks for the winner of the latest result and update three columns according to the result scores.
I tried to add manually a new result object , but the League table doesn’t get updated as expected. What might be the problem? Is the counter api correctly used? It’s meant to update the columns W, SW, and SL, so the counter name is also these names? Also I’m not sure if the where clause is correct-.-
I’ve made the change and it updates the League database when I create new entries using api. But the updates are not as expected… For example, in the W column, I want it to retrieve the current W value, and then add 1 to it. But what I get is 1, it deletes the original value. How should I change the counter api to make this work correctly?
I’ve solved the problem by saving the current object to a variable, and then update the object retrieving the values from the variable plus the number I want to add.