原因是,有超过 100 列我想重用,只有 4 列将被更改,然后作为新记录插入。我最后的手段是加载我想克隆的实体,然后手动设置新实体的属性和加载的实体。
我尝试了以下方法。
<!--- load entity I would like to clone -->
<cfset mainObj= EntityLoad("myBean",{fkOtherId = 2},true)>
<!--- create new entity to save -->
<cfset newObj = EntityNew( "myBean" )>
<!--- clone entity -->
<cfset newObj = EntityMerge(mainObj)>
<cfset newObj.setFirstName(‘John’)>
<cfset newObj.setLastName(‘Smith’)>
<cfset entitySave(newObj)>
已解决:使用
<cfset newObj = duplicate(mainObj)>
<cfset newObj.setId(‘’)>
<cfset newObj.setFirstName(‘John’)>
<cfset newObj.setLastName(‘Smith’)>
<cfset entitySave(newObj, true)>