Copy a List of Objects with reference - Mendix Forum

Copy a List of Objects with reference

0

Hello,

i have an problem adding object to another object.

 

Ihave an object associated to another via other objects. In this example i want to Add a copy of a Team to the Game object.

I retrieve the Team via Game/Match and the List Team_Match

i Copy the List of Teams (MatchTeams) to the toSaveTeamList (there i want to do some changes, but they are not implemented yet)

Then i want to add the toSavesTeamList to the current Game object. However this does not work. You can see in the Screenshot that WoWtcg.Stats.Team_Game (Reference) = empty. I guess this is the problem? how can i set it correctly

asked
3 answers
0

To set which team won the match, create a new extra 1-1 association between Match and Team with a meaningful name, for instance, “Match_VictoriousTeam”. All that this association does, is point out which team won the match.

answered
0

Thanks for your help.

Im not sure however if this is what i wanted. So i guess  your assumption that my datamodel is still correct  in the last point of your answer is correct.

I will try to explain why and what i  want to do:

 

In Essence is want to save results: Matches played, with which Teams and which Team has won how often in a game or in a match. And i want to retrieve all Data of the Team and underlying Data for Statistics.

 

Instead of creating a result object, i wanted to get the data via the game and respective teame objects. (Mainly because i dont know how a result object could look like)

So the GAME object should be the result and create the log of results. Data in there should never be changed after a game has finished.

 

So i thought about the following implementation:

I want to Create Teams. Some parts of the Team (Players) are fixed for all Games. (Later this can be extended to sessions even, as teams are fixed for the complete Session)

Then i want to play individual games with this team. However i want to make changes in the Team, after playing a game.

for example Wincounter for the Game. Then, ideally i want to save the Team with the corresponding individual information (Wins in the match). To Save it, i wanted to use the Team_Game Association. So i want to copy Team and change the Winscounter after each game. So i can retrieve the outcome of a game via Team_Game. (a small result object)

Then after the Match is finished i can use the “old” Team via Team_Match to start again.

 

I have to copy the team and create a link to a game in this scenario. But this is not working. The microflow is triggered when creating a new game btw.

 

I am new to mendix. I have some knowledge in C++ and Java where this seems much easier to implement for me. I think i might not see the forest for the trees :)

I just dont know, how can i set which team won in game object. The link via Match does not work, as its already there. How can the game object look like, and how do i assign a win to a certain team. Thats the underlying problem i cant answer by myselfe at the moment.

 

 

answered
0

I think I see a couple issues that are leading to the problem your describe:

Issues:

  1. Your data model might have an issue or two (the associations between Team and Game/Match might need to be many-to-many (See below)
  2. You have some confusion about of how associations are set (they must be set at the association owner, which is the side of the association in the diagram that has a black dot. If you’re used to using databases with foreign keys, it would be the table that has the foreign key column)

 

How to fix it:

  • Your data model limits a Team to only one Game. I’m guessing that is not correct, in which case you either need a many-to-many relationship between Team and Game. A similar issue might exist for Match, depending on whether a Team can be part of multiple matches. If you change this association to many-to-many:
    • make Game an owner of that association
    • use a Change Object activity to change the Game object
    • change the association Team_Game to set or add the list of Matches to that Team
  • If you data model is actually correct and one Team can only have one Game (or if Team should own that association), then you should use a loop to iterate over the list of Teams. Inside the loop, set the association Team_Game to the appropriate Game
answered