CONTEXT
Adding a node with its field-collection field and inner fields programmatically. Saving the node. Then trying to reach the inner fields - bam! - they are not in the array!
MORE INFO
if I am adding the node manually (not by code) and then trying to get to the inner fields - they ARE there.
[Edit] - The same problem of undefined inner field happens if saving using VBO (Views Bulk Operations module). So, can it be that the structure is bad? However, I have built the collection field using the manual interface only, not by code.
CREATING A NODE WITH FIELD COLLECTION
$node = // Creating a node
$fc_item = entity_create('field_collection_item', array('field_name' => $field_machine_name));
$fc_item->{$field_machine_name}[$node->language][$index][$value_column_name] = $field_value;
$fc_item->setHostEntity('node', $node, $node->language);
$fc_item->save(TRUE);
$node = node_submit($node);
node_save($node);
TRYING TO GET INSIDE FIELD COLLECTION JUST MADE
$value = $node->field_coll_print_authors['und'][0];
print_r($value);
I get:
Array
(
[value] => 278 // This is the field collection item id
[revision_id] => 1533
)
However, what I would have expect, and what I actually DO HAVE when adding a node of the same type by hand is:
Array
(
[field_print_author_last_name] => Array
(
[und] => Array
(
[0] => Array
(
[value] => amir // This is the value I need
)
)
)
HELP
Well, is there any function I have not called in order to attach the field collection item properly to the node? Or something else is missing?
Thanks for your help!