Thinkphp How to check parent table data based on child table conditions

Source: Internet
Author: User
thinkphp Correlation Query

Tour Line 1: Regiment 1: Price 1 (id,price ")
Price 2 (id,price ")

Group 2: Price 1 (id,price ")
Price 2 (id,price ")
I need to filter the group according to the Price field, the relationship model has been fitted, how to encapsulate the Where condition


Reply to discussion (solution)

It is recommended to look at the thinkphp documentation.

thinkphp document write too little only one-to-ones correlation query and does not involve the query based on the condition of the associated table and we often need to query according to the condition of the correlation criterion we do not know this where because how to encapsulate
I want to check the days in line for less than 5 days of regiment
$where ["line.days"] = Array ("ELT", "5"); This is wrong.
That's what I'm dealing with now.
$team = M ("team");
$where = "LineId in (select L.id from line L where L.days < 5)";
$list = $team->where ($where)->select ();
I feel like I'm in a lot of trouble now. There should be a better way to solve it. Ask the God for guidance

If the parent table is associated with a child table, you can directly connect the table by writing SQL.

Give the table structure to see

If the parent table is associated with a child table, you can directly connect the table by writing SQL.
Well, SQL solves it, but wants to know if there's a simple way to do it, like Hibernate, to thinkphp the field of a relational table as its own property.


If the parent table is associated with a child table, you can directly connect the table by writing SQL.
Well, SQL solves it, but wants to know if there's a simple way to do it, like Hibernate, to thinkphp the field of a relational table as its own property.

Then you write SQL directly through the thinkphp ORM.



If the parent table is associated with a child table, you can directly connect the table by writing SQL.
Well, SQL solves it, but wants to know if there's a simple way to do it, like Hibernate, to thinkphp the field of a relational table as its own property.

Then you write SQL directly through the thinkphp ORM.
Is the ORM configured in model? Can you tell me what I just did with PHP?




If the parent table is associated with a child table, you can directly connect the table by writing SQL.
Well, SQL solves it, but wants to know if there's a simple way to do it, like Hibernate, to thinkphp the field of a relational table as its own property.

Then you write SQL directly through the thinkphp ORM.
Is the ORM configured in model? Can you tell me what I just did with PHP?

You write operations directly in the controller SQL

Well, it seems there's no better way than to write SQL. Thank you for your advice.

  • Related Article

    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.