/** * Create a new entity for the data source * * @param KModelContext $context A model context object * @return KModelEntityInterface The entity */ protected function _actionCreate(KModelContext $context) { //Get the data $data = KModelContext::unbox($context->entity); //Entity options $options = array('data' => $data, 'identity_column' => $context->getIdentityKey()); if (!is_numeric(key($data))) { $entity = $this->getTable()->createRow($options); } else { $entity = $this->getTable()->createRowset($options); } return $entity; }
/** * Create a new entity for the data source * * @param KModelContext $context A model context object * * @return KModelEntityInterface The entity */ protected function _actionCreate(KModelContext $context) { //Get the data $data = KModelContext::unbox($context->entity); //Create the entity identifier $identifier = $this->getIdentifier()->toArray(); $identifier['path'] = array('model', 'entity'); if (!is_numeric(key($data))) { $identifier['name'] = KStringInflector::singularize($identifier['name']); } else { $identifier['name'] = KStringInflector::pluralize($identifier['name']); } $options = array('data' => $data, 'identity_key' => $context->getIdentityKey()); return $this->getObject($identifier, $options); }