public function getBucket($db = null)
    {
        /* @var $modelClass ActiveRecord */
        $modelClass = $this->modelClass;

        if ($db === null) {
            $db = $modelClass::getDb();
        }

        if ($this->select === null) {
            $bucketName = $db->quoteBucketName($modelClass::bucketName());

            $primaryModel = $this->primaryModel ?: ActiveRecord::className();

            $primaryKey = $primaryModel::primaryKey()[0];
            $primaryKey = $db->quoteColumnName($primaryKey);

            $this->select = "meta($bucketName).id AS $primaryKey, $bucketName.*";
        }

        if ($this->from === null) {
            $this->from = $modelClass::bucketName();
        }

        return $db->getBucket($this->from);
    }