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.