在ORM之前,如果我想要显示一个规格化表的组合输出,我只需快速执行CFQUERY,在我想要的字段上连接表并显示输出。我就是不能用ORM来理解它。
例如,使用这两个表:
customers
(id,
name,
customerType)
customerTypes
(id,
Name)当customers中的customerType字段链接到customerTypes中的id时,如何创建一个可以加载以显示以下内容的实体?
customers.id, customers.name, customerTypes.name由于某种原因,我经历过的所有ORM关系示例都不能让我理解如何做到这一点。它看起来如此简单,简直要了我的命。任何对此有所帮助的人都将不胜感激!
发布于 2011-02-17 02:55:37
或者另选地
<cfproperty name="type" type="string" column="Name" table="customerTypes" joincolumn="id"> 发布于 2011-02-16 17:28:23
因此,在您的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() />希望这能有所帮助!
https://stackoverflow.com/questions/5012642
复制相似问题