Home > Web Front-end > JS Tutorial > How to solve the problem of the field with the same name in hasOne in thinkphp model

How to solve the problem of the field with the same name in hasOne in thinkphp model

一个新手
Release: 2018-05-23 16:49:12
Original
2955 people have browsed it

There are two tables: play table and type table

play table fields:

id type

type table field:

id title

##type in the play table and id in the type table association.

The model in thinkphp5 is defined as follows:

play model:

class Play extends Model
{
    protected $table = 'wx_play';

    public function type2()
    {
        return $this->hasOne("Type", "id", "type");
    }
Copy after login

type model:

class Type extends Model
{
    protected $table = 'wx_type';
}
Copy after login

Note:

The type2 function in the play model cannot be written as type, otherwise it will be different from the type field in the play table The conflict results in only the fields in the play table being queried, not the objects in the type table.

According to thinkphp5 documentation:

Tips: The type2 method of the Play model is an association definition method, and the method name can be arbitrary Name it, but be careful to avoid conflict with the field attributes of the Play model object
.

The above is the detailed content of How to solve the problem of the field with the same name in hasOne in thinkphp model. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Issues
Why thinkphp has better performance than laravel?
From 1970-01-01 08:00:00
0
0
0
ThinkPHP Why use composer?
From 1970-01-01 08:00:00
0
0
0
thinkphp versions supported by php6
From 1970-01-01 08:00:00
0
0
0
thinkphp upload files
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template