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
Post a Comment