Home > Article > Web Front-end > How to solve the problem of the field with the same name in hasOne in thinkphp model
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"); }
type model:
class Type extends Model { protected $table = 'wx_type'; }
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!