我正在尝试rewhere
或unscope
一个查询,其中原始条件无法使用哈希条件编写:
Reservation.where('block_id IS NULL OR block_id != ?', 'something')
> SELECT `reservations`.* FROM `reservations` WHERE (block_id IS NULL OR block_id != 'something')
尝试到位不起作用:
Reservation.where('block_id IS NULL OR block_id != ?', 'something').rewhere(block_id: 'anything')
> SELECT `reservations`.* FROM `reservations` WHERE (block_id IS NULL OR block_id != 'something') AND `reservations`.`block_id` = 'anything'
但是hash condition
的这个示例可行:
Reservation.where.not(block_id: 'something').rewhere(block_id: 'anything')
> SELECT `reservations`.* FROM `reservations` WHERE `reservations`.`block_id` = 'anything'
我理解这可能是因为在array condition
rails上我不知道我在哪个列中调用where,因此rewhere
将找不到要替换的内容。
有没有办法明确告诉我在数组条件中过滤哪个列?或用哈希条件重写第一个查询(IS NULL OR!= value)?
注意:请不要建议unscoped
,因为我试图仅在这个特定条件下取消/替换,而不是整个查询。
谢谢!
答案 0 :(得分:3)
很抱歉,您还不清楚自己还有其他哪些条款需要保留。您可以使用function downloadFile1(){
var file1 = 'https://example.com/files/myfile.zip';
$.ajax({
TYPE: "POST",
URL: "components.cfc?method=DownloadFile1",
data: {fileId : 3},
success: function() {
window.location = file1;
}
});
}
</script>
访问where子句的数组并对其进行操作,例如:
<cfcomponent output="false">
<cffunction name="DownloadFile1" access="remote" returntype="string">
<cfcontent type="text/html">
<CFQUERY NAME="i">
INSERT into t_terms
(bid, fildid)
VALUES
(
<cfqueryparam value="#session.busid#" cfsqltype="CF_SQL_INTEGER">,
<cfqueryparam value="#url.fileID#" cfsqltype="CF_SQL_INTEGER">)
</CFQUERY>
</cffunction>
又名黑客