Inspecting the $foo
variable showed that I was supposed to use just $foo->image
instead of $foo->image->fid
.
Probably because I have the following lines in my _form_submit
:
if (isset($form_state['values']['image'])) {
$file = file_load($form_state['values']['image']);
$file->status = FILE_STATUS_PERMANENT;
file_save($file);
file_usage_add($file, 'foo', 'foo', $foo->tkid);
$foo->image = $file->fid;
}
Notice the part that says $foo->image = $file->fid;