public function totalRecords(Query $query) { $model = $query->getModel(); $tablename = $model->getTablename(); try { return (int) $this->app['db']->select('count(*)')->from($tablename)->where($query->getWhere())->scalar(); } catch (PDOException $original) { $e = new AdapterException('An error occurred in the database adapter while getting the number of ' . $model::modelName() . ' objects'); $e->setException($original); throw $e; } }
/** * Removes any relationships that are not included * in the list of IDs. * * @param array $ids * * @return self */ public function sync(array $ids) { $pivot = new Pivot(); $pivot->setTablename($this->tablename); $query = new Query($pivot); $localIds = $this->localModel->ids(); foreach ($localIds as $property => $id) { $query->where($this->localKey, $id); } if (count($ids) > 0) { $in = implode(',', $ids); $query->where("{$this->foreignKey} NOT IN ({$in})"); } $query->delete(); return $this; }