Is there a syntax in thinkphp to define a one-to-many or one-to-one relationship? the source code below is described by a guy. the red part below is something I don't understand. please refer:
/**
* User-to-user information table association model
*/
Class UserRelationModel extends RelationModel {
// Define the name of the master table
Protected $ tableName = 'user ';
// Define the association property between the user and the user's email address table
Protected $ _ link = array (
'Userinfo' => array (
'Ing ing _ type' => HAS_ONE, // here HAS_ONE refers to a one-to-one relationship. HAS_ONE is a thinkphp syntax or custom, what is the essence of HAS_ONE here? it is said that HAS_ONE is one-to-many, which is incredible. what is the purpose of this definition?
'Forn N _ key' => 'uid' // Here is the foreign key. what is the role of this place?
)
);
/**
* Automatic insertion method
*/
Public function insert ($ data = NULL ){
$ Data = is_null ($ data )? $ _ POST: $ data;
Return $ this-> relation (true)-> data ($ data)-> add ();
}
}
?>
Reply to discussion (solution)
Haha, it's hard for you all at once, haha!
Is the associated table. One-to-multiple operations can be understood as the operations on the slave table in the master table. Multiple-to-one operations are performed on the master table from the table.
Many-to-many models of TP are not recommended and there are bugs.
We recommend that you use concatenated SQL statements to better understand the association.