English 中文(简体)
ColdFusion ORM关系
原标题:ColdFusion ORM Relationship

在ORM之前,如果我想显示规范化表的组合输出,我只需要做一个快速的CFQUERY,连接我想要的字段上的表并显示输出。我就是无法用ORM来理解它。

例如,对于这两个表:

customers
(id,
 name,
 customerType)

customerTypes
(id,
Name)

当customers中的customerType字段链接到customerTypes中的id时,如何创建一个可以加载以显示以下内容的实体?

customers.id, customers.name, customerTypes.name

由于某种原因,我所经历的所有ORM关系的例子都无法让我理解如何做到这一点。它看起来太简单了,简直要了我的命。任何能让我明白这一点的帮助都将不胜感激!

最佳回答

或者另一种选择

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

请参阅在CFC中连接映射

问题回答

因此,在您的客户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() />

希望能有所帮助!





相关问题
Entity Framework with File-Based Database

I am in the process of developing a desktop application that needs a database. The application is currently targeted to SQL Express 2005 and works wonderfully. However, I m not crazy about having ...

Assistance with CakePHP model relationships

How would I represent the following in a CakePHP model? Product ======= product_id .... Cart ==== cart_id .... Carts_Products ============== cart_id product_id quantity

join across databases with nhibernate

I am trying to join two tables that reside in two different databases. Every time, I try to join I get the following error: An association from the table xxx refers to an unmapped class. If the ...

How are Models (in MVC) and DAOs supposed to interact?

How are models and DAOs supposed to interact? I m in the process of putting together a simple login module and I m unsure where to put the "business logic." If I put the logic with the data in the ...

Convert date to string upon saving a doctrine record

I m trying to migrate one of my PHP projects to Doctrine. I ve never used it before so there are a few things I don t understand. In my current code, I have a class similar to this: class ...

热门标签