How to save term with term references programmatically? I've got a list of terms which I need to add or update programmatically based on their name.

To check if the term exists I'm using a combination of taxonomy_vocabulary_machine_name_load to get the vid and taxonomy_get_term_by_name to get the term if exists. Otherwise I'm creating the term as stdClass object.

When I save the term normal field (using taxonomy_term_save) in format like $term-&gt;field_address[$term-&gt;language][]['value'] = 'some address data' everything works just fine, but when it comes to save relations nothing is begin saved.

I'm saving relations as $term-&gt;field_realization[$term-&gt;language][] = array( 'target_type' =&gt; 'taxonomy_term', 'value' =&gt; $another_term-&gt;tid);.

Where $term-&gt;language = 'und'; and $another_term is a term which belongs to right field Vocabulary declared in Administer.

What am I doing wrong?
If you're using the built-in term reference field type, the column is named tid, e.g.:

$term-&gt;field_realization[$term-&gt;language][]['tid'] = $another_term-&gt;tid;


If you're using an Entity Reference field type, the column is named target_id, e.g.:

$term-&gt;field_realization[$term-&gt;language][]['target_id'] = $another_term-&gt;tid;