Data Mapper and Relationships: Implementation strategies?

后端 未结 3 968
攒了一身酷
攒了一身酷 2020-12-23 17:36

I\'ve almost finished my Data Mapper, but now I\'m at the point where it comes to relationships.

I will try to illustrate my ideas here. I wasn\'t able to find good

3条回答
  •  情深已故
    2020-12-23 18:24

    I too am working through this issue. To start with, I have adapted the Data Mapper pattern from Matt Zandstra's PHP Objects, Patterns, and Practice (2d Ed). I see now that a new edition has come out

    Perhaps the most ingenious part of the setup is the "Collections" objects. I am not sure what language you are using, so I'll spare you the details. Suffice it to say that PHP has an Iterator interface that makes it possible to load an array (map, in other languages) at first and transform the raw data into objects (hydrate?) on the fly, while looping.

    Like you, I am struggling with how to load relationships. What I have found so far is that I can write my massive JOIN query in the Mapper class and create both a dehydrated collection for the target object and sneak in the data on the related objects at the same time.

    I really dislike "Lazy Load" because it leads to so many database queries. It offends my perfectionist sensibilities to know that I am using tens or hundreds of queries to accomplish would could be done in one.

    I, too, am looking forward to more answers.

提交回复
热议问题