How to write thinkphp level 4 association query, online, etc.-php Tutorial

Source: Internet
Author: User
How do I write thinkphp level 4 association queries? how do I write thinkphp level 4 association queries online? Link: How do I associate the aid of A in B, the bid of B in C, and the Cid of C in D?
A --> B --> C --> D
M ("D")-> jion ("A on B. aid =. id)-> jion ("B on C. bid = B. id)-> jion ("C on D. cid = C. id ).


Reply to discussion (solution)

Your expression is wrong.
-> Join ('a on B. aid =. ID')-> join ("B on C. bid = B. id ")-> join (" C on D. cid = C. id ")

Directly write join in join ().

It should be join.

You can directly change jion to join sentences. No problem!

Your expression is wrong.
-> Join ('a on B. aid =. ID')-> join ("B on C. bid = B. id ")-> join (" C on D. cid = C. id ")


This cannot be written. if it is-> join ('a on B. aid =. ID')-> join ("C on B. bid = C. id ")-> join (" D on B. cid = D. id.

You can directly change jion to join sentences. No problem!


Left, right, and inner. it is incorrect if you do not write it.

Look at the final SQL command
Is like this, it meets your requirements

select * from A left join b on a.id=b.aid    left join c on b.id=c.bid    left join d on d.id=d.cid

Look at the final SQL command
Is like this, it meets your requirements

select * from A left join b on a.id=b.aid    left join c on b.id=c.bid    left join d on d.id=d.cid


The generated SQL is like this, but it reports an error, [Err] 1054-Unknown column

1054-Unknown column
Obviously, the field name is wrong. Please check carefully

1054-Unknown column
Obviously, the field name is wrong. Please check carefully


I also know that this error was reported because the name was wrong, but I checked it several times and confirmed that the name was correct.

Run the generated SQL command in mysql manager or phpmyadmin.
See what the original error message is.

Run the generated SQL command in mysql manager or phpmyadmin.
See what the original error message is.


The problem is found. it turns out that the order is wrong. put D to prevent the first, then C, then B, and then.

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.