편집 -Grails의 PARAMS
내 2 개 도메인 클래스에서 각 포트폴리오에 부착 된 지난 5 출판물과 함께, 포트폴리오의 목록을 반환하려고 2.1 createCriteria 문제. 마지막으로 총 5 개의 발행물이 반환되며 각 목록에는 모두 5가 표시됩니다. 쿼리는 해당 특정 인스턴스를 자체 발행물로 반환하지 않습니다. Kellys의 훌륭한 아이디어는 다른 트랙으로 되돌아갑니다.
나는 portfolioTo 클래스에 속하는 출판물의 hasMany 쪽 인 포트폴리오 컨트롤러에서 메소드를 만들었습니다.
난 그냥 자신의 출판물을 나열하는 포트폴리오를 얻을 것 같습니다. eq 포트폴리오를 변경하면 각 포트폴리오 목록에 같은 발행물이 표시된다는 점을 제외하고는 모두 잘 작동합니다.
각 포트폴리오를로드하고 마지막 5 개의 발행물을 나열하려면 어떻게합니까? 이것은 포트폴리오/목록 페이지에서 부분적으로 렌더링됩니다. 이것이 문제 일 수 있습니다. 포트폴리오 목록 작업과 관련이없는 새로운보기에서 렌더링해야합니까 ??
초보자가 grails을 읽고 문서를 읽었으며 제대로 돌아 오지 않는 params 쿼리를 얻는 것 같습니다. 도움
def _webList(){
//def per = Portfolio.properties
def portfolios = Portfolio.list(params.id)
def results = Publication.withCriteria {
eq('published', 'Yes')
order('lastUpdated', 'desc')
maxResults(5)
}
def reportscount = Publication.count()
[ portfolios: portfolios, results: results, reportscount: reportscount]
}
필요한 경우 SQL 로그를 표시 할 수 있습니다.
EDIT
다음 코드 파일 _webList.gsp의 전체 부분이다. 최상위 div -alert가 페이지에로드되지만 div 속성 목록 포트폴리오의 내용이로드되지 않습니다. Kelly의 최대 절전 기준을 사용하면 SQL 로그에서 쿼리가 생성되지만 결과 나 스타일은 반환되지 않거나 아무것도 반환되지 않습니다. 기묘한.!
<div class="alert alert-info" xmlns="http://www.w3.org/1999/html">Permissions apply to <strong>editing</strong> publications.<br>
<div style="display: inline;"><p>Click portfolio name to read or edit publications. Total number of sites: <strong>${rsNumb}</strong> | Total number of publications: <strong>${reportscount}</strong> </p>
</div>
</div>
<div class="property-list portfolio">
<g:each in="${portfolios}" var="portfolioInstance">
<div class="site-listing">
<div><span class="label">Site Name:</span><g:link action="show" id="${portfolioInstance?.id }">${portfolioInstance?.portfolioName?.encodeAsHTML()}</g:link></div>
<div><span class="label">Site Description: </span>${portfolioInstance?.portdescrip?.encodeAsHTML() }</div> <br>
<div><span class="label">Site Administrator: </span>${portfolioInstance?.profile?.portfolioAdmin?.encodeAsHTML() }</div> <br>
<div><span class="label"> Total publications:</span><span class="badge badge-success"> ${portfolioInstance?.publications?.size()}</span> </div>
<!-- whatever else you need here -->
<!-- now iterate through the pubs -->
<g:if test="${portfolioInstance?.publications}">
<g:set var="publicationInstance" />
<ul class="site-publication">
<li class="fieldcontain">
<span id="publications-label" class="property-label"><g:message code="portfolio.publications.label" default="Last 5 published publications:" /></span>
<g:each in="${portfolioInstance.publications}" var="publicationInstance">
${publicationInstance?.id}
<span class="property-value" aria-labelledby="publications-label"><g:link controller="publication" action="show" id="${publicationInstance.id}">${publicationInstance?.encodeAsHTML()}</g:link></span>
<!-- and again whatever else you need here -->
</g:each>
</g:if>
</g:each>
</div>
편집 -
Hibernate: select this_.id as id5_1_, this_.version as version5_1_, this_.date_created as date3_5_1_, this_.last_updated as last4_5_1_,
this_.portdescrip as portdesc5_5_1_, this_.portfolio_name as portfolio6_5_1_, this_.portpublished as portpubl7_5_1_, this_.profile_id as profile8_5_1_,
this_.status as status5_1_,
publicatio1_.portfolio_id as portfolio5_5_3_,
publicatio1_.id as id3_, publicatio1_.id as id2_0_,
publicatio1_.version as version2_0_,
publicatio1_.date_created as date3_2_0_,
publicatio1_.last_updated as last4_2_0_,
publicatio1_.portfolio_id as portfolio5_2_0_,
publicatio1_.publication_content as publicat6_2_0_,
publicatio1_.publication_name as publicat7_2_0_,
publicatio1_.published as published2_0_,
publicatio1_.publisheddate as publishe9_2_0_,
publicatio1_.publishedemail as publish10_2_0_,
publicatio1_.pubproduct_id as pubproduct11_2_0_
from portfolio this_ left outer join publication publicatio1_
on this_.id=publicatio1_.portfolio_id where (this_.status=?)
and (publicatio1_.published=?) order by publicatio1_.last_updated desc
감사합니다.이 말은 나에게 의미가 있습니다. 루비 세계에서 왔을 때, 나는 그 기준에 문제가있었습니다. 당신은이 짧은 공간에서 많은 것을 설명했습니다. 정말 감사. 나중에 다시 시도해보고 결과를 알려 드리겠습니다. – IanN
좋아, 내가 알아 냈다고 생각해. 'firstResult (5)'를 사용하는 답변을 업데이트하고 원하는 모든 것을 수행하는 것으로 보이는 내 테스트에서! 이게 작동하면 알려주세요 ... – Kelly
Kelly, Ok SQL 로그가 쿼리 작업을 표시하지만 gsp 반복이 아무것도로드하지 않습니다. 뷰 코드는 포트폴리오 디렉토리 "_weblist.gsp"내의 부분 템플릿에 있음을 언급해야합니다. 나는 포트폴리오/list.gsp 다음 코드를 표시하지 않는다. –
IanN