getKeyName() as $key) { if ($this->$key) { $query->where($key, '=', $this->$key); } else { throw new Exception(__METHOD__ . 'Missing part of the primary key: ' . $key); } } return $query; } }