The official documentation for ThinkPHP’s associated queries is as follows:

The above join function requires three parameters, which are:

join

The (full) table name and alias to be associated can be written in three ways:

[' full table name or subquery '=>' alias']Copy the code

condition

An association condition can be a string or an array, in which case each element is an association condition.Copy the code

type

The association type, which can be INNER, LEFT, RIGHT, or FULL, is case insensitive. The default is INNER.Copy the code

Different prefix

In this case, the default is to use the same table prefix, such as (shop_), so relational queries using the database model are often written like this:

Order::alias('o')
     ->join('user u', 'o.user_id = u.id')
     ->select();
Copy the code

In the above code, because you are using a model query, both tables are prefixed by default, the full table names of both tables are shop_ORDER and shop_user, and the association type defaults to INNER association.

If you associate a table with a different prefix (e.g., pay_record), the above query statement will not work, then you need to modify the associated statement, modify the code as follows:

Order::alias('o')
     ->join(['pay_record' => 'r'], 'o.pay_id = r.id')
     ->select();
Copy the code

This enables the query to be performed using tables with different prefixes associated with the model.

conclusion

The join parameter in the join function is changed from a string to an array. ThinkPHP is an excellent development framework, the above association is only one of the ways, see the official manual for more ways: ThinkPHP official manual.