The declaration is returned in terms of a relational
ActiveQuery instance
through which the related record can be queried and retrieved back.
A
has-many relation means that there are multiple related records matching
the criteria set by this relation, e.g., a customer has many orders.
For example, to declare the
orders relation for
Customer class, we can write
the following code in the
Customer class:
php
public function getOrders()
{
return $this->hasMany(Order::className(), ['customer_id' => 'id']);
}
Note that in the above, the 'customer_id' key in the
$link parameter refers to
an attribute name in the related class
Order, while the 'id' value refers to
an attribute name in the current AR class.
Call methods declared in
ActiveQuery to further customize the relation.