Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Entity reference in node_save() #688

Open
j-hiertz opened this issue Dec 21, 2015 · 5 comments
Open

Entity reference in node_save() #688

j-hiertz opened this issue Dec 21, 2015 · 5 comments

Comments

@j-hiertz
Copy link

Hi,

I have seeing this post about using entity reference in node_save() #418

I have a different problem,

"field_contrat": {
    "und":{
        "0":{                   
        "nid": form_state.values['n_contrat']           // form_state.values['nid_contrat'] doesn't work
        }
    }
},

This code search on title and not the nid of field_contrat but my title is not unique.

Error : POST http://example.com/?q=drupalgap/node.json 406 (Not Acceptable: Contract: no valid content was found for this title.)

Someone can help me ?

Thanks

@signalpoint
Copy link
Owner

@tsuuki Use target_id instead of nid.

@j-hiertz
Copy link
Author

I have tried this :

"field_contrat": {
    "und":{
        "0":{                   
        "target_id": form_state.values['nid_contrat']
        }
    }
},

and the result :

POST : http://example.com/?q=drupalgap/node.json - 406 - Not Acceptable
{" form_errors ": {" field_contrat ] [ und ] [ 0] [ nid ": " The Contract field is required . "}}

@signalpoint
Copy link
Owner

@tsuuki As you can see, it is still sending the nid for some reason instead of the target_id. Try this:

field_contrat: {
  und: [
    { target_id: form_state.values['nid_contrat'] }
  ]
}

@j-hiertz
Copy link
Author

field_contrat: {
    und:[
        { target_id: form_state.values['nid_contrat'] }
    ]
},  

I've got this :

{"type":"contract","title":"test","body":"test","field_contrat":{"und [{"target_id":"90"}]},"language":"und"}
{" form_errors ": {" field_contrat ] [ und ] [ 0] [ nid ": " The Contract field is required . "}}

@signalpoint
Copy link
Owner

@tsuuki I believe this problem lies with whatever widget you have specified on the "Manage fields" tab in Drupal for your content type. Which widget are you using?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants