【问题标题】:How to save through parent table on one-to-one relationship over primary key如何通过父表保存主键上的一对一关系
【发布时间】:2013-12-17 17:42:54
【问题描述】:

我正在尝试使用第一个表来保存实体,其中表与主键上的一对一关系链接。这是我正在尝试的代码,

tbl6.cfc

component name="tbl6" persistent='true'  accessors="true"{
    property name="id" fieldtype="id" generator="native";
    property name="col";
    property name="tbl7" fieldtype="one-to-one" cfc="tbl7";
}

tbl7.cfc

component name="tbl7" persistent='true'  accessors="true"{
    property name="tbl7id" fieldtype="id" generator="foreign" params="{property='tbl6'}";
    property name="tbl6" fieldtype="one-to-one" cfc="tbl6" constrained="true";
    property name="col";
}

index.cfm

<cfscript>
    ormreload();
    objt6 = entityNew("tbl6",{"col":"tbl6"});
    objt7 = entityNew("tbl7",{"col":"tbl7"});
    objt6.settbl7(objt7);
    objt7.settbl6(objt6);
    entitysave(objt6);
</cfscript>

在上述情况下,ORM 仅保存 tbl6 的记录,但如果我将 entitysave 参数更改为 objt7,它会为两个表存储记录。我不确定我在这里做错了什么。我正在 RAILO 4.1 中尝试这个

请帮忙。

【问题讨论】:

    标签: orm railo


    【解决方案1】:

    啊,我明白了,我只需要在 tbl6.cfc 中的 tbl7 的属性中添加 cascade="all"

    property name="tbl7" fieldtype="one-to-one" cfc="tbl7" cascade="all";
    

    我只是保留问题来帮助别人。

    【讨论】:

      猜你喜欢
      • 2015-04-25
      • 2014-01-13
      • 1970-01-01
      • 2011-04-30
      • 2015-08-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多