0

I am using the ECK module to build custom entities. When using custom entities, the decision must always be made: shall I create a number of entity types or shall I create one entity type with a number of bundles.

From a usability perspective, the latter is obvious since, just as the node system, all entity types can easily be connected in views. It gets harder when different entity types must be used in views.

Apart from that, I assume that there must be a benefit from using multiple entity types. It has something to do with memory that drupal carries around, but it is not clear to me what exactly makes a difference.

I am aware of the benefit of using entity properties instead of fields. However, most of my entities use fields that cannot be replaced by a property.

So the question is: should I in general aim for using more entity types (each of which automatically create one bundle) or should I not worry about performance impact and create all bundles under one (generic) entity type.

1
  • Can you clarify if this is for D7 or D8? Just add the tag "7" or "8".
    – donquixote
    Sep 4, 2017 at 13:14

2 Answers 2

1

I don't have experience with ECK.

But in general I would say:

  • Use entity bundles, if you need different configurations of fields and displays.
  • Use entity types if you need different behavior/functionality, different urls for admin pages, different access logic, etc.

Entities of different types are harder to use together or interchangeably. E.g. an entityreference field can only reference entities of one type. And Views can only list entities of one type.

Performance / memory: With multiple entity types, the total information about all entity types will be bigger. With bundles, the bundle information for one single entity type will be bigger. So some operations might be faster with fewer entity types and more bundles, some operations might be faster with more types and fewer bundles.

2
  • Can you give examples of when the operations will be faster using mofre entity types, and when for using more bundles?
    – Yuri
    Oct 12, 2017 at 3:16
  • My statements about performance are mostly hypothetical. You would have to find out by yourself.
    – donquixote
    Oct 12, 2017 at 11:21
1

This might not be the answer you want as it does not cover performance, but I think that you should choose what makes sense.

The Drupal entities system is about 'families of things'. Think of it as Classes in object oriented programming. An entity is a base class and a bundle is a sub-class that has access to the properties of its parent.

If all the types of entities have no shared fields/properties, create them as different entities. If they share properties, create them as bundles and put the shared properties in the entity. (Or use a combination of entities and bundles if it makes sense.)

But you can use other comparisons too. If you for instance have multiple types of documents (invoices, orders, notes, etc.) that all have different data, it could still make sense to make them as bundles of a 'document' entity.

With respect to memory, I think that ECK creates all entities as a type of EckEntity and then performs some magic to label it differently (please correct me if I am wrong). So you should not need to worry about loading of different classes, it is just the ECK classes.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.