search
HomePHP FrameworkThinkPHPAnalyze a ThinkPHP joint table query case

Analyze a ThinkPHP joint table query case

Mar 09, 2020 am 09:37 AM
thinkphpcase analysis

Analyze a ThinkPHP joint table query case

Analysis of a ThinkPHP joint table query case

What I will introduce to you today is the thinkPHP joint table query case. Two tables are involved here, one is the device table doorcontroller and the administrator table weixin. The weixin_id in the device table is set as a foreign key in the management table, where the foreign key field weixin_id in the master table corresponds to the primary key field id in the slave table.

(Recommended tutorial: thinkphp tutorial)

Analyze a ThinkPHP joint table query case

Device table

Analyze a ThinkPHP joint table query case

Admin Table

In addition, we also need to reference the RelationModel.class.php file during the development process. This file is located in ThinkPHP\Library\Think\Model\RelationModel.class.php and is officially developed. As follows:

<?php
namespace Admin\Model;
use Think\Model\RelationModel;
class DoorcontrollerModel extends RelationModel{
    protected $_link = array(
        &#39;Weixin&#39;=>array(
            &#39;mapping_type&#39;      => self::HAS_ONE,
                &#39;foreign_key&#39;=>"id",//主表的外键对应的从表主键字段
                &#39;mapping_key&#39;=>&#39;weixin_id&#39;,//主表设置的外键
                &#39;as_fields&#39; => &#39;nickname&#39;,
                ),
        );
}

In this way, the result of die(var_dump($arr)) will add a nickname field on the basis of the original data, which realizes the master-slave table related query, by querying only the doorcontroller table At the same time, the nickname of its slave table weixin administrator is also queried.

For more tutorials related to PHP framework, please pay attention to PHP Chinese website!

The above is the detailed content of Analyze a ThinkPHP joint table query case. For more information, please follow other related articles on the PHP Chinese website!

Statement
This article is reproduced at:www.100txy.com. If there is any infringement, please contact admin@php.cn delete

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)