Last week I blogged about ATG unordered one-to-many relationships. Ordered one-to-many is quite similar but a little more complex.
Here again is the same example of players belonging to a team except now the players are a list property of the team.
And here is the SQL.
CREATE TABLE team ( id VARCHAR2(40) NOT NULL, name VARCHAR2(3) NOT NULL, CONSTRAINT team_p PRIMARY KEY (id) ); CREATE TABLE player ( id VARCHAR2(40) NOT NULL, idx NUMBER(2,0),
name VARCHAR2(40), team_id VARCHAR2(40), CONSTRAINT player_p PRIMARY KEY (id) );
Now comes the tricky part. You can never just set the team in the player repository item.
This is because when you do this the idx column in the player table is not set. We could create a repository property and try to set it separately but that is bad practice. You would have to know how many players are already on the team and then set the idx to that number.
What you should do is not allow the team property to be written.
And instead add the player to the team repository item.
players = (Set ) team.getPropertyValue("players"); players.add(player);
Because of this requirement you cannot make the team property required for the player as discussed before.
Again if you have any questions please leave them in the comments.