How do you make multi-table federated queries when using MVC architecture? To find a better solution

Source: Internet
Author: User
How do you make multi-table federated queries when using MVC architecture? To find a better solution


Reply to discussion (solution)

No framework can predict your needs.
You can only organize your data according to the framework constraints.

There is no relationship between a multi-table query and the MVC framework.

Let me tell you a few common ways,

1. Simple, select nested Select:select a.c1,a.c2, (select b.c3 from B where a.c4=b.c5) from A where c6=xxx

2. Simple, select multiple table: Select A.c1,a.c2,b.c3,b.c4 from A, where a.c5=b.c6

3. Flexible join, left JOIN, right join, outer join

4. Union, UNION ALL

5. Two or more of the above mixed use

In fact, there are a lot of difficult SQL queries, the MVC framework can not help you to do multi-table query optimization, so optimizing a query statement, may make your system more efficient.

Represents only personal humble opinion, consultation fee.

There is no relationship between a multi-table query and the MVC framework.

Let me tell you a few common ways,

1. Simple, select nested Select:select a.c1,a.c2, (select b.c3 from B where a.c4=b.c5) from A where c6=xxx

2. Simple, select multiple table: Select A.c1,a.c2,b.c3,b.c4 fr ...



I just want to know, in the development of MVC, how to turn to the original ecological SQL, is directly in the control to write a lot of join these?

No framework can predict your needs.
You can only organize your data according to the framework constraints.



Warrior, could you give me one or two examples.

If you use a framework that has specifications, write it according to its specifications
If not, the native SQL should be available. The same is true for multi-table queries.

If you use a framework that has specifications, write it according to its specifications
If not, the native SQL should be available. The same is true for multi-table queries.



The framework provides some specifications, I use TP to do. Before using the framework, is to write a lot of join statements, found that maintenance is not easy, if you want to modify, to re-understand to read, it is possible to change the wrong, or fan some relatively low-level errors, such as write single quotation marks forget to write.

See Manual 6.23 Association model

I have a question, like the Sales Order table and the Customer table, the user table, the relationship of this table, with object-oriented how to design it

Is there an example in the manual?

If you use a framework that has specifications, write it according to its specifications
If not, the native SQL should be available. The same is true for multi-table queries.



+ + + Yes ...

Reference 3 Floor Wangzhlin's reply: The Multi-table query and the MVC framework have no relation.

Let me tell you a few common ways,

1. Simple, select nested Select:select a.c1,a.c2, (select b.c3 from B where a.c4=b.c5) from A where c6=xxx

2. Simple, select multiple table: Select A ...



Depending on the DB class that the framework encapsulates, look at the manuals or code, or you write them yourself with native SQL connections, and the database part is out of the framework.

Hope to be of help to you.

The landlord can encapsulate into a view directly instantiate an attempt to be able if the site is not very large

What does a multi-table federated query have to do with MVC? You still don't really understand what MVC is.

Enclose your federated query in the model, and the controller will tune it to get the data.



Upstairs says a view packaged as a DB is also a method. I find that very few people use views on MySQL. I don't know why. In fact, views can solve many problems. For example, once the table structure is updated, you just need to recreate the view name unchanged. Instead of having to modify the code. It may be that there are so many new technologies now that everyone is too old to use them.

Thank you for your advice.
In fact, I would like to deal with this kind of table joint query situation, do a better solution for future maintenance convenience. It is best to combine classes. My previous system was to use the original ecological SQL, found that when modified, easy to write wrong is a reason, also not good understanding of the business process.
This method does not know how to use a class to express the relationship between tables and tables.

What is the relationship between multi-table queries and MVC?

My system is the MVC architecture, and a system function, there will be multiple table query situation.
So what I want to know is, when you are using the MVC architecture development, when you encounter this kind of multi-table query, is the direct use of the original ecological Select, or the use of views or stored procedures

is generally the original ecological select, you can go to see the MVC Framework or CMS source code to know.

is generally the original ecological select, you can go to see the MVC Framework or CMS source code to know.


If you use the original ecological Select Connection query data, with what object to receive AH?
  • 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.