Posts

Showing posts with the label Yii2 relations

What are Relationships in Yii2 & How to Promote it?

Image
  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 relations...