Z
Z
Zhenya Starikov2020-07-13 15:45:23
Yii
Zhenya Starikov, 2020-07-13 15:45:23

How to create a table based on an existing yii2?

Hello. I am making an API for a web application, but in the original table in the database, one field is rather poorly arranged (consists of several important parts, and I didn’t need to change it), and for convenience, I divided it into parts in PHP code (split by commas , brackets, periods, etc.), while creating additional fields in ActiveRecord for these parts.

public function getAtt4(){
        return $this->fields[3];
    }
    public function getAttr3(){
        return $this->fields[2];
    }
    public function getAttr2(){
        return $this->fields[1];
    }
    public function getAttr1(){
        return $this->fields[0];
    }

Then I needed to operate on these additional fields, count them as unique, duplicate, etc.
Then I realized that it is better to try to create a migration of the old database, but with changed fields, create a trigger and transfer all records from the old table to the new one. However, I repeat once again that I separated this "bad" field with PHP code and can hardly do the same with an sql query. How to act in such a situation? Suddenly, you can somehow get access to these artificial fields with a sql query?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question