How to auto assign node reference value D7 I have user profile with fields:


date field: "date of birth" (format: y-m-d)
node reference field "card_ref" which should automatically reference to content-type "cards" node. (users cannot change it only view it)


and content-type "cards":


title field
date field (multiple values, format: m-d)


so i'd like to make auto-reference to existing node "cards" which have same date-field value but different format.

For example: 

I have "cards" nodes:
    (title - dates)


Card A - 01.23, 03.11, 05.02
Card B - 02.14, 07.01
Card C - 11.11
Card D - 02.10, 03.02, 05.07, 09.14


After new user registers his account with date of birth: 1977.07.01, I need "card_ref" field to automatically assign him "Card B"
or if entered date of birth: 1234.03.02, "card_ref" should be assigned to "Card D" and so on...

should i use custom module or it is possible to use some existing modules? maybe with views reference field, or rules?

any suggestions please? (for drupal 7)

Thank You..
I found the answer by creating own module.

First I create the View which finds Card nodes by dob field of the user, then inside the hook_user_presave() function I call views_get_view_result() and finally assign the card_ref field like this:

$edit['field_card_ref']['und'][0]['target_id'] = $card;