private function _insertTags($book) { if ($book->Tags) { $this->_table = 'Tag'; $tags = explode(',', $book->Tags); $tagids = array(); foreach ($tags as $tag) { $res = current(parent::_retrieve('TagName', $tag)); if ($res) { $tagids[] = $res->TagId; } else { parent::_create(array('TagName' => $tag)); $tagids[] = $this->lastInsertId(); } } $book->Tags = implode(',', $tagids); $this->_table = 'Book'; } return $book; }
/** * Inserts a new user and returns the newly created User as a domain object * @param User $user * @return <type> */ public function insert(User $user) { $data = $user->toArray(); $id = parent::_create($data); return $this->findById($id); }