Specifying One-to-Many Relationship in ATG Repositories

Monta driving on Flickr
(Photo: Monta driving by Yogma)

Specifying one-to-many relationships is ridiculously easy in Ruby on Rails.  Unfortunately it’s not so straight-forward in ATG repositories.

First you specify the “belongs to” relationship.  In this example the player belongs to a team.


  
  

Then you specify the “has many” relationship.  In this example the team has many players.


  
  

Note the trick is specifying the “shared-table-sequence.”

Here is the SQL for the table that specifies this relationship in our example.

CREATE TABLE team_players
(
  team_id     VARCHAR2(40)  NOT NULL,
  player_id   VARCHAR2(40)  NOT NULL,
  CONSTRAINT team_players_pk PRIMARY KEY (team_id, player_id),
  CONSTRAINT team_players_players_fk foreign key (player_id) references players (id),
  CONSTRAINT team_players_team_fk foreign key (team_id) references teams (id)
);


2 thoughts on “Specifying One-to-Many Relationship in ATG Repositories

  1. hi pavithra,
    thanks for your comment.
    i’m not sure what you mean though. are you saying that the column-name and id-column-names should be switched in my code example? i believe it’s correct.
    thanks,
    frank

Leave a Reply

Your email address will not be published. Required fields are marked *