how do you define types if you custom select in a rails query -


my query looks this:

@posts = post.includes(:last_comment)     .joins("left outer join read_marks on posts.id = read_marks.post_id , read_marks.user_id = #{user.id}")     .where(:postr_id => postr.id)     .select("posts.*, read_marks.comments_cache rm_comments_cache, read_marks.timestamp last_read_at") 

but when call @posts.each{|post| post.last_read_at} returns string , not datetime.

why don't try using readmark model?

@posts = post.includes(:read_marks)     .joins("left outer join read_marks on posts.id = read_marks.post_id , read_marks.user_id = #{user.id}")     .where(:postr_id => postr.id)  @posts.each{|post| post.read_marks.timestamp} 

this method cleaner, , uses activerecord in way designed.

if want use original query, can parse date manually.

@posts.each{|post| date.parse post.last_read_at }


Comments

Popular posts from this blog

c# - How to set Z index when using WPF DrawingContext? -

razor - Is this a bug in WebMatrix PageData? -

visual c++ - Using relative values in array sorting ( asm ) -