I have a custom plugin that's saving an entry successfully. While saving the entry I'm setting our "merchant" field (an entries field, limit=1) like so:
<?php # ... $entry = newEntryModel(); # set the sectionId, typeId, authorId, and some other fields... $entry->getContent()->merchant = (isset($data['merchant']) ? [$data['merchant']->id] : null; // $data['merchant'] is an EntryModel
This appears to be fine in the CP. I can see and edit the related entry.
However later in the application I have to update this entry and when updating the entry, I'm only updating a single field. While debugging the EntryModel that I'm trying to save I see that if I var_dump $entry->merchant I get an ElementCriteriaModel yet when I dump $entry->getContent->merchant I get 'null'.
My log shows the following error:
2014/10/31 18:25:46 [warning] [application] Craft\ContentModel->merchant failed validation: Merchant cannot be blank.
According to this tweet it seems like dumping $entry->getContent()->merchant should be returning a ContentModel instead of null.
EDIT: I've confirmed that everything works as expected if the field is NOT marked as required. However, this can't really be a solution - I need to make sure that the client cannot leave this field blank.