Hi,

I was wondering what the best way is to store stuff to the database.

I am developing a module with an entity in it. Currently the entity has about 30 fields. I was wondering if this is the most efficient way (in terms of performance) or should I keep the entity low on fields and attach fields to it through the form api.

Interested in hearing your thoughts.

Best wishes,

Marc

Comments

blueminds’s picture

Your suggested approaches do not really make a difference.

If you want to optimize for performance create a custom field with all data fields you need (in other words creating a multi-field field) and than attach this field to your entity by creating a new bundle. Using standard fields will result in two tables per field so in your case it will be 60 db tables. Creating custom field involves a lot of coding - you have to create own formatter, widget, etc.. however having two tables instead of 60 is quite a difference.

Another option would be using standard fields with mongodb as field data storage. But this approach will involve some restrictions in matter of database querying - to get data from db you will have to use either field entity query or query mongodb directly.