2011-02-16 61 views
5

在ORM之前,如果我想要顯示規範化表的組合輸出,我只需要快速執行一次CFQUERY,將所需表連接到我想要的字段並顯示輸出。我無法使用ORM將我的頭包裹在它周圍。ColdFusion ORM關係

例如與這兩個表:

customers 
(id, 
name, 
customerType) 

customerTypes 
(id, 
Name) 

你會如何創建可以加載顯示一個實體的客戶鏈接到customerTypes一個id,當customerType場下?

customers.id, customers.name, customerTypes.name 

我出於某種原因走過的所有ORM關係示例都無法讓我明白如何去做。它看起來很簡單,它會殺死我。任何幫助解決這個問題,將不勝感激!

回答

1

或可替代

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

看到Join mapping in a CFC

+0

+1 - 我不知道你能做到這一點,非常有用。 – 2011-02-16 22:24:59

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() /> 

希望幫助!