2013-08-05 4 views
3

다음 문제가 발생했습니다. 의 지시에 게시물 필드를 게시 내 문제가 데이터베이스에서 이전 및 다음 게시물을 얻을 수 있습니다Squeryl : Option [T] where 절에있는 객체를 비교하는 방법?

case class Post (

    id: Int, 
    slug: String, 
    title: String, 

    @Column("postText") 
    text: String, 
    isVisible: Boolean, 
    created: Timestamp, 
    lastUpdated: Timestamp, 
    published: Option[Timestamp] 

) extends KeyedEntity[Int] 

: 나는 클래스가

는 모양 포스트를 말한다. 내가 겪었던 문제는 게시 된 필드가 Option [Timestamp]입니다. 나는이 같은 Squeryl 쿼리 생성 :

val nextPost = from(postTable)(p => 
     where((p.published > post.published) and p.isVisible === true) 
     select(p) 
     orderBy(p.published asc) 
    ).page(0, 1) 

을 그리고이 결과는 SQL에서 보았을 때 나는 이런 식으로 뭔가 보았다 를 "... post.published WHERE> 일부 (".... ") .. . " 물론 SQL 쿼리에서 구문 오류가 발생했습니다.

설명서를 보았지만 대답을 찾을 수 없습니다. 이미 squeryl MySQL의 쿼리 건설 명확한 버그가 있습니다

UPDATE

... 슬릭로 전환 할 생각입니다.

Select 
    Post9.lastUpdated as Post9_lastUpdated, 
    Post9.published as Post9_published, 
    Post9.postText as Post9_postText, 
    Post9.slug as Post9_slug, 
    Post9.id as Post9_id, 
    Post9.isVisible as Post9_isVisible, 
    Post9.title as Post9_title, 
    Post9.created as Post9_created 
From 
    Post Post9 
Where 
    ((Post9.published > 2013-08-01 14:21:25.0) and (Post9.isVisible = true)) 
Order By 
    Post9.published Asc 
limit 1 offset 0 

볼 쿼리 생성자는 날짜를 포맷하는 방법 ...

내가 슬릭로 전환하고있다 : 나는 쿼리를 생성

val x : Timestamp = post.published.getOrElse(new Timestamp(0)) 
val nextPost = from(postTable)(p => 
    where((p.published.getOrElse(new Timestamp(0)) > x) and p.isVisible === true) 
    select(p) 
    orderBy(p.published asc) 
).page(0, 1) 

으로 돌아가 셨습니다.

+0

어떤 버전의 Squeryl이 었습니까? –

+0

내 sbt 구성을 살펴 보았습니다. 0.9.5-6 –

+0

이동하고 시간이 없다면 이해하지만 재현 가능한 테스트 케이스를보고 싶다면 함께 해결할 수 있습니다. 이것이 버그 인 경우. Squeryl List (https://groups.google.com/forum/#!forum/squeryl)에 여기 또는 (선호) 게시 할 수 있습니다. –

답변

0

나는이를 확인하지만, 당신이 Some(...) 부분을 제거하는 데 도움이해야

p.published.get > post.published.get 

을 시도하지 않았다.

주의 : SQL "NULL == NULL"이 true가 아니기 때문에 쿼리가 diffetently 동작 할 수 있습니다 (NULL ...). 시도해 볼 수도 있습니다 getOrElse(...).

1

나는 이것이 DB 객체가 아닌 타임 스탬프를 비교했기 때문이라고 생각합니다. squeryl을 사용하는 차이를 이해하는 것이 중요합니다.

그래서, 당신은 대신 사용해야합니다

p.published gte post.published 
p.published.~ > post.published 
p.published === post.published 
p.published gt post.published 

참고 문헌을 :

http://squeryl.org/inserts-updates-delete.html

와 "덜이"/ "더"가 필요하다 실제로 모든 예제

http://squeryl.org/schema-definition.html

합니다.

관련 문제