I need advice about the correct way to utilize the Drupul database. I am making a site where a lot of data is going to be entered about each user, and that data will be used to give feedback to the user.
I have figured out how to create profile types and gather data for each profile type.
I was wondering if I should not be using profiles for this purpose - should I make forms and database tables for user information some other way? I am concerned that the data will not be easily available because I am not just displaying the profiles for each user - I will need to process and display it with custom algorithms.

But instead of having one or two tables with a column for each piece of data, the Drupul profile data is spread out over many tables, with each data field having its own table, such as dr_field_data_field_favoritecolor_group`

Comments

ayesh’s picture

Drupal's default Field Storage is to store field data in separate tables and JOIN them when necessary. But it comes with the advantage of Views integration, access control, etc.

However, if you have a fixed data structure and if you are willing to take time to write your own entity CRUD forms, database schema, views integration and other necessary functionality, creating a custom entity would be the best move.

rodeored’s picture

That's what I was afraid of. That sounds like a lot of joins, especially to get statistics from multiple profiles.

nevets’s picture

Personally I would not worry about the joins and if you use a module like entity cache, the data is cached by the system.

Besides the advantages mentioned above, core plus the entity API module makes it straightforward to work with entities should you need some form of custom processing.

jaypan’s picture

Nevets is correct. Use the entitycache module, and the joins are irrelevant.

Contact me to contract me for D7 -> D10/11 migrations.

rodeored’s picture

That sounds great. The cache would address of efficiency of the queries, but my question doesn't have anything to do with efficiency. I probably wasn't very clear .

My problem is: I haven't figured out how to access the profile data at all, without building all those queries from scratch, (which means constructing queries "by hand" with a lot of left joins) or else hardcoding the access for every field in the profile2 profile object. If I can do that, then I will happily use the profiles for storing my data.

jaypan’s picture

All core entities, and most contributed modules that provide entities have a _load argument of some sort to be able to load items of that entity. At worst, you can use entity_load(). This will give you the loaded entity, with which you can access the fields.

node_load()
user_load()

etc.

Profile2 also has a load function, but I don't remember what it is off the top of my head. Look in the .module file, and you should find something.

Contact me to contract me for D7 -> D10/11 migrations.

rodeored’s picture

Thanks, here is a list of the Profile2 methods.
http://drupalcontrib.org/api/drupal/contributions!profile2!profile2.modu...

I have tried $profiles=profile2_load_by_user($user->uid,'lifestyle') ;
The profile data is not in its own array in the $profiles object, so there's no way to return or even to collect them by iterating through them. If I have hundreds of fields, I would have to hard code each field.
$fields["field_age_group"]=$profiles->field_age_group

I haven't tried the other load functions yet, but I did discover that I can also use views.
I wasn't sure I could access the data in a view instead of just displaying it, but it turns out you can.
This video describes how to make a view of Profile2 data.
https://www.youtube.com/watch?v=xRmqHcATeKk

And this page describes how to access the data in the view.
https://drupal.org/node/342132

nevets’s picture

From your initial post you state

 I will need to process and display it with custom algorithms. 

which would imply you need to know the field names in order to apply the custom algorithms, since if you iterate over the set of fields how would you know what processing to apply?

rodeored’s picture

If I can obtain the data without using the field names, I don't have to add the field names to the code that obtains the data everytime I add a new profile field.

nevets’s picture

How are you trying to process the fields?

rodeored’s picture

I'm gathering information and creating advice based on that information. One piece of data could influence many different kinds of advice, and one piece of advice could come from many different pieces of data. To give a simplistic example, if the user wakes up at 10:00, AND the user misses the bus, the advice would include recommendations for getting up earlier.