Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Index method not obeying columName() it tries to create the index using the field name instead #62

Open
lsrzj opened this issue Nov 13, 2018 · 0 comments

Comments

@lsrzj
Copy link

lsrzj commented Nov 13, 2018

When trying to use this kind of construct $builder->integer('userId')->columnName('user_id')->index('user_id_token_index')->nullable(); Fluent is giving me the error that there is no column named userId on the database. Obvious, because I changed the column name and I'm not using the class's field name. So I tried a workaround that I don't know if it's the correct form to implement it, but solved the issue. Bellow the code snippets:

Field.php

/**
 * @param string|null $name
 *
 * @return Field
 */
public function index($name = null)
{
    if (!isset($this->fieldBuilder->getMapping()['columnName'])){
        $columnName = $this->getName();
    } else {
        $columnName = $this->fieldBuilder->getMapping()['columnName'];
    }
    $index = new Index(
    $this->metaDatabuilder,
      [$columnName]//$this->getName()]
    );

    if ($name !== null) {
        $index->name($name);
    }

    $this->callbackAndQueue($index);

    return $this;
}

FieldBuilder.php, added a method to get the mapping information

public function getMapping() {
    return $this->mapping;
}

Another workaround is to do like this on the mapping file:

$builder->integer('userId')->columnName('user_id');
$builder->index('user_id');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant