We’ve already seen how to select data from a single database table using Active Record (AR). We’ll show you how to utilise AR to unite several related database tables and retrieve the resulting data set in this part.
It is advised that primary-foreign key restrictions be defined for tables that need to be connected to implement relational AR. The limitations will aid in maintaining the relational data’s consistency and integrity.
To keep things simple, we’ll use the database design depicted in the entity-relationship (ER) diagram below to explain the examples in this section.
Execution of a Relational Query
Performance of Relational Queries
As previously stated, the eager loading strategy is primarily employed in scenarios where we need to retrieve a large number of linked objects. By joining all required tables, it generates a large complex SQL query. In many circumstances, a large SQL query is preferable since it makes filtering based on a column in a related table easier. However, in other circumstances, it may not be effective.
Consider the situation where we need to locate the most recent posts as well as their comments. Assuming each post has ten comments, a single large SQL transaction will return a large amount of redundant post data because each post will be repeated for each comment.
Process of in-depth Documentation
Another significant benefit of the Yii framework, in comparison to all other frameworks, is that it did come with a detailed documentation system.
The Yii framework provides a platform that is not only useful for creating a standard e-commerce website, but also for providing the greatest possible user experience. It offers a large number of custom features in comparison to other frameworks such as Magento or WordPress. It assists in the automation of corporate activities in addition to managing the internet presence.
I hope this guide has helped you understand the assertion of Yii2’s Promote Relationships. To acquire a professional solution for your project, hire dedicated developers; a professional answer to your project’s problems.