hasRelation($field) && $this->hasField($field . 'Ids')) { $collection = $this->get($field); $ids = array(); $names = new \stdClass(); foreach ($collection as $e) { $id = $e->id; $ids[] = $id; $names->$id = $e->get('name'); } $this->set($field . 'Ids', $ids); $this->set($field . 'Names', $names); } } }