Resolving the naming problem of Belongstomany () module name in THINKPHP5

Source: Internet
Author: User

This article brings the content is about THINKPHP5 in the Belongstomany () module name of the naming problem resolution, there is a certain reference value, the need for friends can refer to, I hope to help you.

Recently in the development of CRM management system with TP5 a problem is that when the association query (many to many) with the BELONGSTOMANY function hint model does not exist, the following to see the specific problem.

function Introduction

My usage in the project

And look at the model layer in my TP5 again.

F_role is an association model
Ref_user_role is an intermediate table (many-to-many relationships have an intermediate table)
role_id FOREIGN Key Name
USER_ID is the primary key of F_user

This writing is entirely in accordance with the manual to write the theory that there is no problem, but the time to run to error:

Tip Fuser module does not exist, but my module name is F_user this naming method.
The reason is that there is a problem with naming rules for module names.

Solutions

Later do a short debugging to find the cause of the problem:
You need to modify the Parsemodel method in the Belongstomany method in thinkphp/think/model.php


Change 1 in the picture to 0 because

Turn the naming style into a little bit

Finally change the naming style and run the test again.

Get the data (including the associated data can be successful).

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.