ColdFusion ORM 关系映射

5
在ORM出现之前,如果我想要显示规范化表的组合输出,我只需快速执行CFQUERY,在所需字段上连接表并显示输出。但使用ORM时,我无法理解它。
例如,有这两个表:
customers
(id,
 name,
 customerType)

customerTypes
(id,
Name)

你如何创建一个单一实体,以便在客户类型字段与客户类型ID相关联时,可以加载并显示以下内容?
customers.id, customers.name, customerTypes.name

我之前看过一些ORM关系的例子,但是似乎总是无法理解如何实现。这个问题看起来很简单,但却让我苦恼不已。希望能有人帮我解决这个问题!

2个回答

1

所以在你的Customers CFC中,你需要像这样:

<cfproperty name="customerType" type="CustomerTypes" fieldtype="many-to-one" cfc="CustomerTypes" fkcolumn="id" lazy="true" />

然后,您应该能够转储一个Customers对象的实例,并查看它是否具有customerType属性,因此您可以编写类似于以下内容的代码:

<cfset cust = entityLoad("Customers", 1) />
<cfset type = cust.getCustomerType().getName() />

希望这能有所帮助!

1

或者另一种选择是

<cfproperty name="type" type="string" column="Name" table="customerTypes" joincolumn="id"> 

查看在CFC中加入映射


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接