How does the multi-to-many relationship model of laravel be used in distributed situations, such as user tables on another server?

Source: Internet
Author: User
Tags node server
Recently encountered a problem in the background interface of an app.
Currently, the server where the article table resides is as a separate node, while the user table is on another node server.

Article Server

    • Article table

    • Article Details table

    • Article Favorites Intermediate Table

User server

    • User table

The problem now is that the article server accepts the USER_ID from the app client, and then queries it only by writing the associated query and then flattening out the format of the JSON response package to return. Unable to enjoy the convenience of the Laravel model relationship, rather than elegant.

Is there any way to use the model without a table?

Reply content:

Recently encountered a problem in the background interface of an app.
Currently, the server where the article table resides is as a separate node, while the user table is on another node server.

Article Server

    • Article table

    • Article Details table

    • Article Favorites Intermediate Table

User server

    • User table

The problem now is that the article server accepts the USER_ID from the app client, and then queries it only by writing the associated query and then flattening out the format of the JSON response package to return. Unable to enjoy the convenience of the Laravel model relationship, rather than elegant.

Is there any way to use the model without a table?

You are the equivalent of a small distributed system, ah, two servers in the middle or in the interface or service to associate a better way.
There is no need to use many-to-many models, and the relational model of Laravel cannot handle these complex scenarios.
It is not considered that the use of the model relationship is elegant, the decoupling and service between the system, the interface is the more elegant implementation of the scheme.

Another question, if your article table often use user_id, why not add a user_id in the article Table redundant field?

  • 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.