3

A table named demo,now need to partition it just like demo1,demo2,demo3,....,demo10

So how to partition the table on Yii2?

I probably known should add a method getTableName in Model.

tanteng
  • 648
  • 1
  • 6
  • 11

1 Answers1

0

Change the related model

the tableName function return the table name

class YouModel  extends \yii\db\ActiveRecord
{

    public static function tableName()
    {
        return 'yourTableName' . $YourNumber ;
    }
    ......
ScaisEdge
  • 131,976
  • 10
  • 91
  • 107
  • are you saying the the above coede will create a partition ? – Muhammad Omer Aslam May 23 '20 at 23:40
  • 1
    @MuhammadOmerAslam No. He's giving idea on how to handle the partitioned table in model – pown Jun 09 '22 at 09:33
  • @pown that is not the question that is asked. OP says "So how to partition the table on Yii2?" maybe the question needs more clarification. also the above will throw error because there is nothing defined for `$YourNumber` neither any value is passed as params – Muhammad Omer Aslam Jun 16 '22 at 10:13
  • @MuhammadOmerAslam you are not asking .. are commenting .. if you have a real question post a new question with proper detail .. and eventually comment me the link .. anyway this answer if not for partitioning table but for manage a multi tenancy table – ScaisEdge Jun 16 '22 at 10:43
  • 1
    its not something to get into conflict/debate I think, what is clearly written i posted in my comment too. and YES your code will throw error – Muhammad Omer Aslam Jun 16 '22 at 10:45