AndrewSimm
Well-known member
I am working on a Quote addon that allows users to post quotes and authors to a page. Once the user submits the quote, author, etc I check if the author currently exists in the author table and add it if it does not. This part works with no issues. Last, once the author exists in the authors table I want to update the quote table with the author id from the authors table. I am getting am message telling me to use "forceSet" and I am not exactly sure what this does or if I should be using it. I also don't know how to use it.
PHP:
protected function _postSave()
{
$author_name = $this->author;
$quoteId = $this->quote_id;
$repo = $this->repository('Andrew\Quotes:Author');
$finder = $repo->findAuthor();
$author = $finder->where('author',$author_name)->fetchOne();
$authorId = '';
if(!empty($author))
{
$authorId = $author->author_id;
}
$this->updateAuthor($author, $author_name, $authorId);
$this->updateQuoteAuthorId($quoteId, $author_name, $authorId);
$this->_postSaveBookmarks();
}
protected function updateQuoteAuthorId($quoteId, $author_name, $authorId)
{
if(empty($authorId))
{
$this->updateBasedOnAuthorName($author_name, $quoteId);
}
else
{
$this->updateBasedOnAuthorId($authorId, $quoteId);
}
}
protected function updateBasedOnAuthorName($author_name, $quoteId)
{
$repo = $this->repository('Andrew\Quotes:Author');
$finder = $repo->findAuthor();
$author = $finder->where('author',$author_name)->fetchOne();
$authorId = $author->author_id;
$repo = $this->repository('Andrew\Quotes:Quote');
$finder = $repo->findQuote();
$quote = $finder->where('quote_id', $quoteId)->fetchOne();
$save = $quote;
$save->author_id = $authorId;
$save->save();
}
protected function updateBasedOnAuthorId($authorId, $quoteId)
{
$repo = $this->repository('Andrew\Quotes:Quote');
$finder = $repo->findQuote();
$quote = $finder->where('quote_id', $quoteId)->fetchOne();
$save = $quote;
$save->author_id = $authorId;
$save->save();
}