Update programmatically Group Audience I have made a hook_node_insert which when I create a group content of type A, it create a node group. I want to associate my type A with the created group with the field audience.
I have changed the field group audience like that 

$nodeA-&gt;group_audience = array(
    LANGUAGE_NONE =&gt; array(
        '0' =&gt; array(
            'gid' =&gt; $group-&gt;gid,
        ),
    ),
);


But it doesn't save the data into the database. I have tested with node_save but I have the error that primary key nid is duplicated.

Thank
Unless you're changing the $node inside a node_save() or something, your changes won't make it into the database unless you add a node_save() after the change to $node.