数据映射器设计模式和多对多关系


Data Mapper design pattern and many-to-many relationship

我读过以下关于Domain Model设计模式和Data Mapper设计模式的文章:

  • http://phpmaster.com/building-a-domain-model/
  • http://phpmaster.com/integrating-the-data-mappers/
  • http://www.devshed.com/c/a/MySQL/Building-an-ORM-in-PHP/
  • http://www.devshed.com/c/a/MySQL/Building-an-ORM-in-PHP/1/

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

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

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
现在你有以下对:(第一个,PNG),(第一个,GIF),(第二个,

JPEG),(第二个,PNG),(第三个,GIF)[你可以看到第四个和BMP不在列表中] 现在你看到如何表示0,1或多个连接