views:

42

answers:

3

I'm creating a web application and I just want to know how to think about Drupal's db coming from an MVC background. I have tables to represent people's data such as SSN, First Name, Last Name, Zip Code, Address, Language, Location. Now on the front end I want to create a form to populate this information for a bunch of subjects (people). I have my database normalized so the Zip Code has its own table (with a foreign key link to the person table). The "person" table has stuff such as First Name, Last Name, Address etc... and the "language" table will have the different language abbreviations (again with a foreign key back to the person table).

I would like to know how to move something like this to drupal's schema. I know I could create my own tables and link them back to the "node" table and then I guess build my forms to accept user input...but is this the suggested way to do it? I was looking at webform, but it seems this should be used for simpler forms where the database isn't normalized and everything is just stored in one large table. I'm not sure, but I would definitely love to hear what you guys think...and if you could point me to some resources that'd be great.

+2  A: 

Drupal is flexible enough that you can create whatever tables you want and then write code to link them back to the node table. However doing this will mean that you end up with a lot of code which is very specific to your schema, and is not very interoperable with other Drupal modules.

You will find that you get on better with Drupal if you mostly do things the Drupal way. And only go for a very customized solution where you are doing something which isn't covered by standard Drupal modules.

For example you may find that the profile module fits your needs as far as standard information about people goes. The location module (specifically user location) will cover users addresses. By using these modules you are more likely to find other modules which work with them in future and overall you will find you have less code to write.

One thing you may find useful is the migrate module for getting your existing data into Drupal.

Jeremy French
Thanks Jeremy...the profile and location module seems to be for users who've signed up (as users to the site) though. I needed a form for capturing persons (subjects) data. But thanks for the comments...its given me more insight. I could also probably use some tables from those modules.
berto77
+2  A: 

It sounds like you're just storing information and the subjects (people) won't be users of the Drupal site.

Leveraging the node and CCK modules to make this happen would remove most of the development work. For example, each of your tables (e.g. Person, Zip Code, Language) could be represented by a content type with a number of fields. The foreign keys would be represented by node reference fields. So the Person content type may have one or more node references to nodes of type, Language.

The migrate module seems well used (626th most popular of 4000+ modules used in at least 10 distinct Drupal sites), but it may be easier to whip up your own migration script, but I'm not familiar with either your situation, your familiarity with Drupal's API, or the migrate module.

Node reference fields display as links to the referenced nodes by default, but can be themed to load and display the referenced node instead (e.g. displaying Language information in a Person node). There's a handy screencast that illustrates how to go about theming node reference fields to load and selectively display the referenced nodes' contents.

James
Ok, so the node references are basically "foreign key" links - makes sense..thanks
berto77
+1  A: 

Coming from an MVC background you may not like how Drupal stores data in the DB.

Profile module was mentioned, but I find I get more flexibility with Content Profile and CCK combined.

I've written some migration scripts before from Coldfusion to Drupal, and it's not too involved.

Kevin
I will check out the content profile.
berto77