ThinkPHP Association query problems

Source: Internet
Author: User
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 ')

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.