ThinkPHP associated query I used the latest version 2.0 & nbsp; I have written the association definition in the MODEL. now I want to query the data in the controller. the relation (true) is described in the manual) method, but an error is prompted: Model: relation the method you requested does not exist. why? Please help me solve the problem. thank you for your question about the big ThinkPHP Association query.
I used the latest version 2.0 to write the association definition in the MODEL.
Now we need to query data in the controller.
The relation (true) method described in the manual prompts an error: Model: relation the method you requested does not exist.
What's going on? Thank you for your answers.
Source code
Join definition (in MODEL)
Public $ _ link = array (
'Lytype' => array (
'Maping _ type' => HAS_ONE,
'Class _ name' => 'lytype ',
'Foregin _ key' => 'typeid ',
),
Associated query (in controller)
$ Ly = new lyModel ();
$ List = $ ly-> relation (true)-> find (1 );
Error message:
Model: relation the method you requested does not exist
------ Solution --------------------
$ Ly = new lyModel ();
New LyModel ()
------ Solution --------------------
Class UserModel extends RelationModel
Inherits the RelationModel class
/**
+ ----------------------
* Perform Association query
+ ----------------------
* @ Access public
+ ----------------------
* @ Param mixed $ name join name
+ ----------------------
* @ Return Model
+ ----------------------
*/
Public function relation ($ name ){
$ This-> options ['link'] = $ name;
Return $ this;
}
------ Solution --------------------
1. declaration class
Class NewsModel extends RelationModel
{
}
2. query
$ News = D ('news ');
$ Data = $ News-> Relation (true)-> find ();
Dump ($ data );
------ Solution --------------------
Instantiate with D ('New') or m ('new', 'ralationmodel ')