Displaying 1 result from an estimated 1 matches for "replies_top".
2012 Jul 18
5
Any comment on adding #cast and #cast! to ActiveRecord::Relation?
...the data
from a sql string wherever it''s used.
Here''s an example of where I''d use this:
class Topic < ActiveRecord::Base
has_many :replies
scope :by_most_recently_replied, joins(:replies).group(''topics.id'')
.select(''topics.*, MAX(replies_topics.written_on) AS
latest_reply_written_on'')
.order(''latest_reply_written_on
DESC'').cast(latest_reply_written_on: :datetime)end
>> topic = Topic.by_most_recently_replied.first>> topic.latest_reply_written_on.class=> Time
The cast is applied to postgre...