eZ Platform Discussions

eZ Publish entities / Symfony doctrine entities - ORM Relationship?

version2

#1

Hi all!

How does eZ Platform manage ORM in database? Does entities use Doctrine?

Is it posible to make a relation between my entities with Location, Content, or ContentInfo eZ Platform entities?

Thanks.


#2

Hi @skrosoft

By default, eZ does not use ORM, so you will have to install it and configure it yourself. There is no reason why you couldn’t use your mappings to make relationships to eZ entities, it will just have to be on ID level, not on object level.

Check out one of our bundles for inspiration:


#3

Thank you for your answer @emodric

I was talking about Object Level Relationship.

Doctrine was already installed on eZ Platform 2.x.

So, if eZ Platform doesn’t use Doctrine, what kind of ORM uses eZ Platform to persist data on DB?

(NetgenInformationCollectionBundle doesnt seems to work with eZ Platform 2.x)


#4

It uses Doctrine DBAL only and its query builder. Check eZ\Publish\Core\Persistence\Legacy namespace in eZ kernel for details.

As for info collector bundle, I know it doesn’t work with v2 yet, but reading the code might be useful :slight_smile:


#5

@skrosoft eZPublish uses its own content-to-database layer, which we might call an ORM (and usies dotrine dbal to abstract away db access).

Unlike what you get with Doctrine, ezpublish basic ‘entities’ are by themselves quite rich, as they implement an EAV model: a Content has many versions, and each Version has values for the Fields. Also, a Content has one or more Locations. In terms of persistence, this means that

  • the definition of the different types of Content happens in the backoffice by default, not via annotations on code
  • the core set of database tables used is made of at least 7 tables
  • the mapping is not as simple as ‘1 entity = 1 table’
  • there is a single big table which holds the values for all Fields of all versions of all Contents, regardless of their ContentType
  • as a developer, you are not supposed to access directly the database tables, but always use the ezpublish API

In order to create relations between Content entities, there are 2 types of Fields that you can use: ObjectRelation and ObjectRelations.

In order to relate a Content to an external piece of data, you could start by adding to your Contents a Field of type id, and store in it the ids of your separate entities. After getting comfortable with that, you might end up wrapping the logic for managing this Field into a new FieldType class.

A couple of bundles that might come in handy if you are used to Doctrine:

  • kaliop migrations: similar to doctrine migrations, but instaed of writing sql you create yaml files that let you use the rich content model of eZ to describe what you want to change

  • kaliop ezobjectwrapper: gives a default way where you could store custom business logic tied to your Contenht/Location entities, and tie them to external entities if needed. A good alternative to custom FieldTypes in some cases


#6

ps: as @emodric said it is not uncommon to install the Doctrine ORM bundle to manage other data in the db and join it to eZ native Contents/Locations.

It is generally just not as simple as doing a single DQL query in your custom entities though (when you select an eZ Content out of its db table you generally have to check for its publication state, visibility, language, version, custom state, section and access permissions to name but a few conditions. That’s why you don’t want to create that bit of sql by yourself…)


#7

Kudos @gggeek for the detailed response! :slight_smile:


#8

Thank you @gggeek for your detailed response. I am friendly with ez so, I know most of theses points but hope it will help someone.

Both kaliop bundles looks good, I’ll check that, thank you for the information !!! “ezobjectwrapper” looks perfect in my case :slight_smile: it seems to be what I was looking for.


#9

If eZ Platform does not use Doctrine ORM then why it is required in composer.json? https://github.com/ezsystems/ezplatform/blob/master/composer.json#L35


#10

@JarJak Probably to allow easier custom development, without need to install and configure ORM manually.


#11

I am looking for a solution equivalent to this doctrine command but for ezplatform database:
php bin/console doctrine:schema:create --dump-sql > dump.sql

I don’t want to use mysqldump or another similar tools to avoid dependencies.

Any idea?


Ok … all internet seems to recommend mysqldump …


#12

mysqldump is your friend :slight_smile: