I've also seen custom queries in plugins that could be prevented through fully utilizing the DB models.
Didn't really know where else to put this, but wanted to share for other devs, a proper way for simple updates. This doesn't entirely eliminate the need for specific queries in all cases, but can dramatically simplify some DB updates while being quicker and safer by utilizing the DB models and PDO that OW utilizes:
public function update(CLASS_BOL_Name $data )
{
$ex->andFieldEqual('column-index', $search);
$dto = $this->findObjectByExample($ex);
if ( empty($dto) )
{
return;
}
$dto->column=$update;
$dto->column=$object->value;
$this->save($dto);
return $dto->id;
}
Working Example:
public function updateSubscription(OXPWAPRO_BOL_Subscriptions $subscription )
{
$ex = new OW_Example();
$owuserid = OW::getUser()->getId();
$ex->andFieldEqual('owuserid', $owuserid);
$dto = $this->findObjectByExample($ex);
if ( empty($dto) )
{
return;
}
$dto->owuserid=$owuserid;
$dto->endpoint=$subscription->endpoint;
$this->save($dto);
return $dto->id;
}