Limit node reference to 1 per user & per referenced node, Drupal 7 I am trying to limit the creation of a node reference to 1 per user and per referenced node. 
More specifically: I have a content type named Debate and another one called Vote. Vote has a node reference field (from URL widget) called *debate_ref* to the Debate type. What i'm trying to achieve is for each user and for each debate to have only one vote 
i.e. when a user tries to create a 2nd vote node on the same debate node then he will recieve a message saying "You have already voted!".

"Unique field" module does the job but after the user attempts to save his 2nd vote node. What i would like to achieve is to deny access to the user who attempts to re-visit the "node/add/vote/nid" form if he has already voted for the specific debate.

Any help?
A solution is to use hook on form_alter inside a custom module :

function MYMODULE_form_alter(&amp;$form, &amp;$form_state, $form_id) {
 if($form_id == 'vote_node_form') {
    global $user;
    $nid = explode('/', current_path());
    $nid = end($nid);
    // I'm sure that next part can be done waaaaaaay better
    $query = db_select('node', 'n')
    -&gt;condition('entity_type', 'vote', '=')
    -&gt;condition('uid', $user-&gt;uid, '=');
    $query-&gt;join('your_entity_ref_field_table', 'e', 'n.nid = e.entity_id');
    $query-&gt;condition('your_reference_column', $nid, '=');
    $query-&gt;groupBy('e.entity_id')-&gt;execute();
    // I'd advice to do a dpm($query-&gt;fetchAssoc();) to check if I didn't make a mistake         :)

    if(!empty($query)) {
            // We force the user to go on any page if he has already casted a vote on that debate (you can i.e create a page with a word of explanation)
            drupal_goto('/');
            //or do whatever you want here
    } else {
            // If not, we let him go to the normal node creation page
    }
  }
}