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

Auto-prefix doesn't work on selects, but does on insert. #63

Open
fryiee opened this issue Aug 6, 2019 · 2 comments
Open

Auto-prefix doesn't work on selects, but does on insert. #63

fryiee opened this issue Aug 6, 2019 · 2 comments

Comments

@fryiee
Copy link

fryiee commented Aug 6, 2019

As title. Example here (prefix is wp):

$supportCategory = SupportCategory::where('category_number', $row['Support Category Number'])->first();

var_dump($this->table); shows support_categories

$supportCategory = SupportCategory::create([
                "category_name" => $row["Support Category Name"],
                "category_number" => $row["Support Category Number"]
            ]);

var_dump($this->table); shows wp_support_categories

@fryiee
Copy link
Author

fryiee commented Aug 6, 2019

Using the following getTable as a workaround:

public function getTable()
    {
        if(isset($this->table)) {
            $prefix =  $this->getConnection()->db->prefix;
            return substr($this->table, 0, strlen($prefix)) === $prefix ? $this->table : $prefix . $this->table;
        }

        return parent::getTable();
    }

@cdwieber
Copy link

I had a similar issue with updating existing models. I narrowed it down to Model.php:400 -
$model->setTable($this->getTable());.

By the time it gets here, many times the table has already been prefixed, and it hits this two additional times. So for a save method it was trying to write the query for local.wp_wp_wp_appointments. @fryiee 's workaround has resolved this for me for the time being, but when I get some time I'd like to investigate further and see if I can't come up with a permanent fix. I'll make a PR if so.

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

2 participants