1

我已阅读以下有关Domain Model设计模式和Data Mapper设计模式的文章:

关系很容易one-to-one。谁能向我解释我该如何组织many-to-many支持?

例如:我们有树形表:和posts,其中最后一个表是支持帖子和图像之间关系的表。imagesposts_href_imagesmany-to-many

4

1 回答 1

0
posts:
post_id | post data...
1 | "first"
2 | "second"
3 | "third"
4 | "fourth"

images:
image_id | image_data...
1 | "JPEG...."
2 | "PNG...."
3 | "GIF..."
4 | "BMP..."

posts_href_images:
post_id | image_id
1 | 2
1 | 3
2 | 1
2 | 2
3 | 3

Now you have the following pairs: (first, PNG), (first,GIF), (second,JPEG), (second,PNG), (third,GIF) [and you can see that fourth and BMP are not in the list] Now you see how can you represent 0, 1, or multiple connections

于 2012-05-07T19:01:06.970 回答