Vikrant Dubey
Vikrant Dubey

Reputation: 86

Multiple relations in Yii 2.0 ActiveRecord Model

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

Answers (2)

Iman Tumorang
Iman Tumorang

Reputation: 131

You can use gii extension to generate the relations gii

Upvotes: 0

Álvaro Herrero
Álvaro Herrero

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

Related Questions