Reputation: 86
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.
Upvotes: 4
Views: 993
Reputation: 151
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.
Upvotes: 0