I'm using the saveRelations
method in the RelationsService
to save entry relationships in a plugin I'm working on. Everything is working as expected, however, saveRelations
is returning null
on success, which seems odd.
Here is a portion of the code I'm working with:
public function addCategoryRelation(CategoryModel $category, EntryModel $entry)
{
$field = $craft()->fields->getFieldByHandle('handle');
$handle = $field->handle;
$relations = $category->$handle;
$relationsIds = [];
/**
* Get the ids for the relations.
*/
foreach ($relations as $entry) {
$relationsIds[] = $entry->id;
}
if (!in_array($entry->id, array_values($relationsIds))) {
$relationsIds[] = $entry->id;
return craft()->relations->saveRelations($field, $category, $relationsIds);
} else {
return [
'error' => 'Entry already saved.',
];
}
}