zf2 - Zend\Db - What do Model, Entity, Hydrator, Mapper, TableGateway do and how it all links together?
Asked Answered
K

2

5

Please explain what

  • Model
  • Entity
  • TableGateway
  • Mapper
  • Hydrator

do and how it all works together in zf2 application.

please don't give links to blogs articles. I need simple big picture explenation.


As far as I understand these are the same:?

Model    == Entity
Hydrator == Mapper
Kusin answered 17/5, 2013 at 8:21 Comment(0)
K
7

If we take for example one db table. Then:

  • Model will represent one row class where class variables would be columns.
  • Entity is the same concept as Model used by Doctrine.
  • TableGateway is parth from Table Gateway pattern. It will have information about table name. This is place where all query methods will be located. Used in all zf2 examples.
  • Mapper is parth from Data Mapper pattern. It is more advanced way of handling the same problem what TableGateway is doing.
  • Hydrator is changing your select query row results from array to Model object. If not provided then zf2 will use ArrayObject instead.
Kusin answered 19/5, 2013 at 7:16 Comment(0)
P
1

Model can be a entity, but strictly, model is entity with business logic inside. for simple system, model is a entity.

Mapper is a way used to deal with Object persistence in RDBMS, it's a tool to convert each other between object properties and row columns.

Hydrator is a tool to exchange data between datasource and objects (models or entities), the datasource can be a RDBMS or something else (Web Service, NoSQL etc.).

Mappers contain more detail solutions on persistance by RDBMS, such as, Lazy loading, Caching, transaction and so on.

TableGateway is an abstracting with DB tables, but tables is often not the persistence of real world objects, it provides us a way of access relation data in an OOP style.

Photogenic answered 21/6, 2013 at 9:4 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.