2013-01-11 33 views
1

我使用CF9 ORM -的ColdFusion 9 ORM一到一個多CFC

我有一個對象模型,在那裏我有可能有一到一個關係到一個特定的對象的多個對象。有沒有辦法具體說明與兩種潛在CFC之一的反向關係?

CFC 1A(ProblemType1):

property name="Product" cfc="Product" fieldtype="one-to-one" fkcolumn="productID" ; 

CFC 1B(ProblemType2):

property name="Product" cfc="Product" fieldtype="one-to-one" fkcolumn="productID" ; 

CFC 2:

property name="Problem" fieldtype="one-to-one" cfc=???; 

可否使用一個接口,用於此?要麼...?

回答

3

CFC 1a和CFC 1b都可以是父實體CFC 1的子類。CFC 1應與「產品」具有關係,該關係將由兩個子類繼承。然後,CFC 2可以在其關係中指向CFC 1。

樣品實體:

/** CFC 1 **/ 
component persistent="true" { 

    property name="Product" cfc="Product" fieldtype="one-to-one" fkcolumn="productID"; 

} 

/** CFC 1a **/ 
component persistent="true" extends="baseProblem" { 

    // problemtype1 specific properties go here 

} 

/** CFC 1b **/ 
component persistent="true" extends="baseProblem" { 

    // problemtype2 specific properties go here 

} 

/** CFC 2 **/ 
component persistent="true" { 

    property name="Problem" fieldtype="one-to-one" cfc="baseProblem"; 

} 

如果你採取這種方法,你可能需要考慮inheritance mapping,特別是discriminatorColumndiscriminatorValue屬性。在不知道數據庫架構如何設置的情況下,很難就此提供進一步的建議,但文檔應該讓您開始。

+0

我對ORM相關遺傳的理解是缺乏的。感謝您的鏈接和指導。 –