我在持久化cfc中有一个自定义属性,看起来像这样:
property name="last_live_request"
fieldtype="one-to-many"
cfc="Accreditation"
fkcolumn="pers_ky"
setter="false"
orderby="ACCR_KY desc"
where="status_doma_ky in (27,28) and rownum = 1"
;
目的是加入一对多的Accreditation记录,并且只检索最近的一个。问题是它不起作用。
就像在普通PL_SQL中一样,行数在排序之前被评估,因此我没有得到最近的记录。
在普通的PL-SQL中解决这个问题的方法是做一个像这样的子选择,这样我们首先得到记录,然后选择顶部记录:
select *
from (
select *
from JOU_V_REV_PEACC
where status_doma_ky in (27,28)
and pers_ky = [nnn]
order by ACCR_KY desc
)
where rownum = 1
所以我的问题是,我如何在我的cfc属性实现这个结果?
我找到了一个解决方法:
// Get the max id using the formula attribute (note, requires SQL, not HQL)
property name="LAST_LIVE_ACCR_KY" setter="false" formula="
select max(peac.accr_ky)
from JOU_V_REV_PEACC peac
where peac.status_doma_ky in (27,28)
and peac.pers_ky = PERS_KY
";
// Set up the property
property name="last_live_request" persistent="false" default="";
// Load the required Accreditation using a custom function
function getlast_live_request() {
return entityLoadByPK("Accreditation", this.attr('LAST_LIVE_ACCR_KY'));
}