开发者

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                |
+----+-------------+-------------------+

Noti开发者_如何学Goce 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?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜