What Is a Relationship in Yii2 and How Does It Promote Relationships in Yii2?
Active Record has already demonstrated how to select data from a single database table (AR). In this section, we'll demonstrate how to use AR to connect several connected database tables and extract the final data set. In order to create relational AR, it is advised that primary-foreign key limitations be set for the tables that must be connected. The restrictions will help to preserve the integrity and consistency of relational data. To make things clear, we'll use the entity-relationship (ER) diagram below to illustrate the database design for the examples in this section.
Execution of a Relational Query The simplest approach to execute a relational query is by reading a relational property of an AR instance. A relational query will be conducted, connecting the two pertinent tables and filtering using the unique identity of the current AR instance if the property has never been accessed. The results of the search will be saved as one or more instances of the relevant AR class to the