11

I'm learning about the Entity API. I have a simple extra table that I'd like to "drupalize" so that I can use it in Views, for example.

I've read quite a bit, watched a few videos, looked at quite a few examples. I'm stuck on the concept of bundles. I understand what bundles are (e.g. node types are bundles of the node entity).

But for my use there will only ever be one bundle. In the examples I've seen the bundle is stored in the database table; this is not necessary for me as it would be the same value stored against every record. So I was thinking I could somehow skip this, or have my entity always return a standard string for bundle.

Have I misunderstood? Do bundles always have to be implemented, and implemented at database table level?

9

Yes a bundle is always, always necessary for entities.

If you don't define your own bundle(s), the entity system will assign a default one with the same name as the entity type for you, and that one will be used.

If you've only got one bundle, and only ever plan to have one bundle, then you don't need to have a specific field in your entity table for it. As you suggest in your question it would always be the same, so would be redundant and just add extra overhead (however tiny) to your db queries.

If you think you might need to distinguish between different sub-types of your entity at some point though, it would be worth building that in right from the start; it really depends on your use case.

| improve this answer | |
  • Although, if an entity has to have a bundle, how is it that the bundle itself can be an entity(?!) – artfulrobot Sep 21 '12 at 17:43
  • 1
    I'm pretty sure that's just talking about the idea of abstracting CRUD functionality onto a generic entity type, and re-using that throughout the system so all objects (entities, bundles, fields, etc) can take advantage without having to implement their own. In terms of a Drupal entity (node, user, etc) a bundle is very much a different thing. If a bundle was indeed a Drupal entity, it could itself have bundles, which doesn't make sense :) – Clive Sep 21 '12 at 17:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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