1

Ok, I'm going to toss out an example of what I'm trying to do with US states and counties, but I'm not looking for a module to handle them... It's just an example.

Assume I have two content types, the US State and US County content types. So now I have some nodes of US State (alabama, alaska, etc) that have some fields, like maybe population size, square feet of territory, etc. Now I have counties, so I've got some N counties that belong to alabama, some for alaska, etc., each as its own node.

How can I make a US County node know what US State node it belongs to? How can I make US State nodes know what US County nodes belong to them? For like querying in a view or whatever, basically the functionality of foreign keys in a SQL table. This seems like it would be very simple and obvious to do, but I must be missing it.

Remember, this is just example data types, I'm not really working with US States and US Counties, so I don't want some specific module for them, just the idea of how to setup content types and the like to have foreign keys.

And if anyone knows, how efficient is this? If I'm dealing with millions or maybe billions of nodes with some hierarchy of relations, how well can drupal query this stuff with joining linked data from multiple content types based on these "foreign keys"? Is it 10x slower than mysql tables with foreign keys, faster than that?

edit: Using Drupal 7. Maybe this will make things clearer: I've tried making a taxonomy vocabulary or whatever, but I don't see how to specify relations between nodes. I can say a US County is under US State, but how can I say "Baldwin County" is in "Alabama"? Where do I put that data in?

  • Try to keep to one question per post. If you're worried about performance, you're going to need to be more specific about what you're doing ("millions" vs. "billions" is a pretty big difference) and that's certainly better to ask as a separate question once you have an idea of what module(s) you are going to use. – Patrick Kenny Apr 23 '12 at 15:16
  • 2
    There are three modules that do this: Node Reference, Entity Reference, and Relation. For a comparison, see: drupal.stackexchange.com/questions/13862/… – Patrick Kenny Apr 23 '12 at 15:19
0

Relating US Counties to US States sounds like something Taxonomy would be great at, considering it has built in Hierarchy.

However, for Node Relations the best module for the job is References. If you will have users adding content that will reference another node, you can utilize Node Reference URL Widget. That will allow you to, for instance, create an "add county" link, which when clicked brings the user to an add county page that is already populated with the correct state.

0

I'd look into Node References or Taxonomy depending on what version of drupal you are using and whether or not you are trying to create a hierarchy structure in your site.

  • I've tried making a taxonomy vocabulary or whatever, but I don't see how to specify relations between nodes. I can say a US County is under US State, but how can I say "Baldwin County" is in "Alabama"? Where do I put that data in? – user173342 Apr 23 '12 at 15:11
  • If you created a vocabulary called state, that contained 50 terms, eg "Alabama," "Alaska" etc, you could set up where any content could be tagged once from this vocabulary. You could even use this to generate the node title of your state content if you wanted, but could then also, using views, for example, list all county type nodes tagged with it as well. – Jimajamma Apr 23 '12 at 15:19

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.