I am using organic groups, which creates an entity reference field on a content type. Now i have a custom module that is supposed to create a node programatically and i am having trouble with saving the entity reference field.
Error message i get:Notice: Undefined property: DatabaseStatementBase::$nid
Here is what i have tried:
$qry= db_select('node', 'n')
->condition('type', 'some_og_content_type', '=')
->condition('title', 'some_title', '=')
->fields('n', array('nid'));
$ogRef= $qry->execute();
$ogNid = $ogRef->nid;
$node->og_group_ref['und'][0] = array('target_id'=>$ogNid);
//i also tried this
$node->og_group_ref['und'][0]['target_id']=$ogNid;