4

I am trying to define relations in ActiveRecord Model Class, but the problem is our database is too large and has many relations. So is there a simpler way to declare relation in only one model so that Yii can understand the relation for every other model it is related to.

public function getBill_details()
{
    return $this->hasMany(bill_details::className(),['company_bill_id'=>'id']);
}

public function getCompany()
{
    return $this->hasOne(company::className(),['merchant_c_id'=>'id']);
}

I have created two functions for two relations. Similarily I have around 80 relations in one table only so is there an simpler way of doing it.

2 Answers2

0

If you could use innoDB and set the relations on the database before Gii generates the models, Gii would generate the models with the relations for all tables.

antichris
  • 2,015
  • 1
  • 17
  • 17
Álvaro Herrero
  • 141
  • 1
  • 8
0

You can use gii extension to generate the relations gii

Iman Tumorang
  • 121
  • 2
  • 7
  • 25