What Is a Relationship in Yii2 and How Does It Promote Relationships in Yii2?

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

Reading a relational property of an AR instance is the simplest way to run a relational query. If the property has never been accessed, a relational query will be run, joining the two relevant tables and filtering with the unique identifier of the current AR instance. The search result will be saved as an instance(s) of the corresponding AR class to the property. The relationship query is only executed when the associated objects are first accessed, which is known as the passive loading strategy.

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.

Conclusion

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.

Get in touch with us for more!

Contact us on:- +91 987 979 9459 | +1-980 428 9909

Email us at:- sales@xceltec.com

Visit our website: https://www.xceltec.com/

Sorry, you must be logged in to post a comment.

Translate »