1

I'm creating an application where I want a content type with quite a few extra fields. When I try and retrieve this type programatically the DB is showing that each of the extra fields are stored in their own table. This is fine I guess but will mean my queries/views will be quite long and any changes to the fields via the admin console will require a bit of back end work.

Is this just a price I have to pay or is there another option? If possible I want to be able to administer the fields as normal (changing their names say and maybe adding new ones) and not have this affect my code too much - so in essence I want my cake and eat it!

As always, thanks again...

(drupal-7.14 Lamp)

1

You can use views to create the queries for you so you can easily change your views in the back-office without the need of messing with custom code.

Or if you want to write the views yourself use the EntityFieldQuery class to create custom views without writing joins yourself because this is defenitivly not the way to do it.

You can load the full node object programmaticly by using node_load() and filter the fields you need. This loads the full node object so this can slow down the system when loading lots of nodes using node_load_multiple().

And finally if you think this isn't straightforward enough consider writing your own entity where you can add all fields inside your custom table(s) and get the entity data with simple queries.
When using the views module you can add your entity to the views data by using hook_views_data.
There is also the possibility of adding fields to your entity so this opens a lot of opportunities if really needed. It's a bit of extra work to install, especially the first time u use entities so you have to see if the budget allows room for testing and debugging.
An introduction to entities

1
  • Many thanks for the speedy and considered reply Jurgen. Better get my gloves off and start exloring these options. Jun 2 '12 at 13:32

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.