ColdFusion ORM:我可以指定在加载时传递给相关实体的init参数吗?

CfS*_*ity 4 coldfusion orm

假设我有一个Page实体,它可以有一个关联的Document实体数组:一个简单的一对多关系.

<cfcomponent entityName="Page" persistent="true" table="pages">

  <!--- A Page can have many Documents --->
  <cfproperty name="document" fieldType="one-to-many" cfc="Document" fkColumn="pageID" inverse="true">

</cfcomponent>
Run Code Online (Sandbox Code Playgroud)

但是,每个Document都需要知道其文件系统目录的路径,并且此属性的值可能因上下文而异,因此它不是持久性的,需要在实例化时传入.

<cfcomponent entityName="Document" persistent="true" table="documents">

  <!--- This value needs to be set so the document knows its location --->
  <cfproperty name="directoryPath" persistent="false">

  <!--- Many Documents can belong to one Page --->
  <cfproperty name="page" fieldType="many-to-one" cfc="Page" fkColumn="pageID">

  <cffunction name="init" output="false">
    <cfreturn this/>
  </cffunction>

</cfcomponent>
Run Code Online (Sandbox Code Playgroud)

如果我手动或使用Bean Factory为页面加载文档数组,我可以将directoryPath变量指定为传递给Document init()方法的参数.但是在这里,文件的加载是由Hibernate自动完成的.

有没有办法在ORM加载时将init参数传递给相关对象?

我知道我可以在加载后循环遍历文档并指定目录,也许这是最佳实践,但是在init上将值传递给每个文件似乎更有效.可能吗?

Ily*_*tov 5

通过文档查看,似乎没有办法按照您的要求进行操作.

我建议的一件事是,不是循环遍历文档来设置属性,您可以在Page对象中设置属性并从Document访问它.

所以在加载Page后你会有类似的东西Page.setDocumentPath(documentPath);.

然后在显示文档时你可能会有类似的东西document.getPage().getDocumentPath();.