CyberJunkie
CyberJunkie

Reputation: 22674

Codeigniter disallow identical table rows

I have the following table that allows users to add other users as friends

+----+-------------+-------------------+
| ID | User_ID     | Friend_ID         |
+----+-------------+-------------------+
| 1  | 102         | 213               |
| 2  | 64          | 23                |
| 3  | 4           | 344               |
| 4  | 102         | 213               |
| 5  | 102         | 90                |
| 6  | 64          | 88                |
+----+-------------+-------------------+

Notice above that user 102 has added user 213 twice. I want to dissallow duplicate rows. Using active record, how can I disallow addition of user as friend if the user is already a friend?

Upvotes: 0

Views: 130

Answers (1)

eugene_che
eugene_che

Reputation: 1997

Obviously, you are using id as a primary key for your table. I can suggest to use a complex primary key, combining all the table fields. Still this is not a good design approach. As alternative you could make a table decomposition.

Upvotes: 1

Related Questions