当我在Grails中使用RestfulController来保存对象的数据时,如何阻止客户端将更改应用于相关的子对象?
给出以下域类:
class Language {
String name
}
class TranslationText {
Language language
String text
}
以下是TranslationText的POST数据:
{
"language": { "id": 1, "name": "InvalidName" },
"text": "Some Text"
}
在这里,我想引用现有的语言资源(ID = 1),但我不希望客户更改名称。
如何使用文本和语言(基于ID)保存此资源,但丢弃无效的语言名称属性?
我想以尽可能最小的方式修改RestfulController,尽可能地保留默认行为。
答案 0 :(得分:0)
我认为你需要配置'cascade'映射属性。这将告诉GORM驱逐链接实例,因此它不会在Hibernate会话中,更改为新名称并刷新到DB:
<html>
<link rel = "stylesheet" href = "styling.css?version=3"></link>
<body>
<div id='acctdetails' style='padding-left: 15% '>
<?php
echo "USERNAME: ". $_SESSION["dynau"];
?>
OR Date: <input type='text' placeholder='OR Date' name='ordate' value='<?php echo date('M, d, Y');?>'>
OR ID: <input type='text' placeholder='OR ID' name='orid'>
Payor : <input type='text' placeholder='Payor' name='payor' >
</div>
<center>
<form method="POST">
<?php
$result = mysqli_query($link,"SELECT * FROM account_db");
echo"<html>";
echo "<script>";
echo "function calculate(amount, id){
document.getElementById('total' + id).innerHTML = parseInt(document.getElementById('copy' + id).value) * amount;
var x=parseInt(document.getElementById('total' + id).innerHTML);
var y = document.getElementById('sumtotal').innerHTML;
var a = y.split(' ');
var z = parseInt(a[1]) + parseInt(x);
document.getElementById('sumtotal').innerHTML = 'Total: ' + z;
}";
echo "</script>";
echo"<center>";
echo "<form method='POST'>";
echo "<br></br>";
echo "<table style='border:1px solid black' id='thetable' name='pleasework'>";
echo"<th>FILES</th>";
echo"<th>AMOUNT</th>";
echo"<th>NO. OF COPIES</th>";
echo"<th>TOTAL AMOUNT</th>";
$counter = 0;
while($row = mysqli_fetch_row($result))
{
echo"<tr>";
echo "<td >$row[1] </td>";
echo "<td align=center>$row[2] </td>";
echo "<td align=center>
<input type='number' id='copy" . $counter . "' onkeyup='calculate(" . $row[2] . ", " . $counter . ")'>
</td>";
echo "<td align=center id='total" . $counter . "'></td>";
echo"</tr>";
$counter++;
}
echo"<tr>
<td id='sumtotal'>TOTAL: 0</td>
</tr>";
echo "</table>";
echo " <br><div style='padding-left: 15px'><input type='submit' id='btn1' value='Transact' name='transaction' onclick='javascript: window.print()'></div>";
echo"</center>";
echo"</html>";
?>
</center>
</body>
</html>
参考:http://docs.grails.org/3.1.x/ref/Database%20Mapping/cascade.html