2

I have two content types account and device. device has a reference field named reference_account_number and it's referencing account_number in account, but the unique key for account is a composite key account_number and environment.

I used auto node title module to generate the node title based on account_number for account, and let reference_account_number map on to the node title of the account nodes. So my problem comes up when I try to do feed import when there are duplicate account_number but different environment. The reference_account_number only map onto the account node that has matching node title.

Is there any way to reference another node based on two fields? I was thinking about adding a environment field to device content type as well

Ideally, I would like this scenario happens when a user creates a new device content.

User enters the account number and environment, upon completion, user views the content just created, and reference account number provides a link to all existing account that matches the account number user inputted for the device content, same thing goes for environment

Thanks

2
+25

Is there any reason why you could not just reconfigure auto node title to generate a node title based on a composit account number and environment -- say, something like "[account_number] ([environment])"? It seems like if you did this, then your reference_account_number configuration would remain unchanged, your feeds will not get confused, and users can still add references by typing the account number only thanks to the standard autocomplete feature of node references.

If you did not like the way that "[account_number] ([environment])" looks in the output of your site, you could alter the render array, maybe in a hook_process_field. For a good description on hooking the Drupal 7 render process, see The Scary Render Array.

  • Yea, I thought about that. But I have a php file that generate xml file from these two content types. This would be a problem since I don't wanna print out the title in this case. – lusketeer Jul 25 '12 at 22:07
  • I am not sure under what conditions you do not want to print the title. If you mean that you do not want the title to appear in the xml, the feeds module will, I believe, allow you to easily fix up the node at import time. So, you should be able to regenerate the title from the account number and environment before node_save is called, which should make your references work out. Of course, this means that your reference account number in your device xml would be "[account_number] ([environment])"; hopefully this is okay, because I think it would be a lot harder to make a two-field relation. – greg_1_anderson Jul 25 '12 at 22:56
  • Yea, I don't want reference account number displaying both account number and environment. I can just make no reference at all, and the xml will output just fine, but I can't make a view based on the relationship. I tried field reference, it can reference fields, but it's not good since I have to use feeds importer to import csv file – lusketeer Jul 25 '12 at 23:11

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.