我对 cfwheels 有几个问题(n:m 关系)
这是我的数据库架构
rights righthaspath path
-id -------| -id --> -id
-role -->-rightid (FK) | -url
-pathid (FK)------|
我的模型 /Models/Right.cfc
<cffunction name="init">
<cfset hasMany(name="righthaspath",shortcut="path")>
<cfset nestedProperties(associations="righthaspath")>
</cffunction>
/模型/路径.cfc
<cffunction name="init">
<cfset hasMany(name="righthaspath")>
</cffunction>
/模型/Righthaspath.cfc
<cffunction name="init">
<cfset belongsTo("path")>
<cfset belongsTo("right")>
</cffunction>
在我的控制器中
<cfset tmp= model("right").findall(include="righthaspath")>
所以,来自 cfhweels 的 sql 语句是:
SELECT rights.id,rights.Role,righthaspaths.id AS righthaspathid,righthaspaths.pathID,righthaspaths.rightID FROM rights
LEFT OUTER JOIN righthaspaths ON rights.id = righthaspaths.rightID
但我想要一个像这样的三个表的 sql 语句
SELECT
*
FROM
rights
INNER JOIN righthaspaths on rights.id=righthaspaths.rightID
INNER JOIN paths on righthaspaths.pathID=paths.id
你能帮忙吗?
PS:我不能包括路径,例如
<cfset tmp= model("right").findall(include="righthaspath,path")>
因为我有一个错误
An association named path could not be found on the right model.