Table Joining

I have two tables named Customer,and CustomerAllPoints.

Primary key of the Customer table is msisdn.

that msisdn also a foreign key for the CustomerAllPoints table and points is another column of this table.

Here, I want to join those two table and want to retrieve all columns data of customer table according to the ‘points’ column of CustomerAllPoints having only 30 points.

I am using yii frame work and I am very newer to the framework.

Thank for any kind of help,

Have you already read through the "Getting Started" section of the guide?

If not yet, you have to. :)

I can’t tell the details here, but the basic approach is something like the following:

  1. Use Gii to create ActiveRecord models for Customer and CustomerAllPoints tables.

If you have correctly specified the foreign key constraint between the tables, Gii will create a relation between the AR models.

Is the relation "Customer has one CustomerAllPoints" or "Customer has many CustomerAllPoints" ? If the former, you may have to modify the gii-generated code.

  1. Modify the views of "Customer" to display the related "CustomerAllPoints" data using the relation.

  2. Modify "search" method of the CustomerSearch model so that it can filter the result by the attributes of the related CustomerAllPoints model.


An example:

class Customer extends ActiveRecord


    public function getBigOrders($threshold = 100)


        return $this->hasMany(Order::className(), ['customer_id' => 'id'])

            ->where('subtotal > :threshold', [':threshold' => $threshold])