Displaying 1 result from an estimated 1 matches for "latest_reply_written_on".
2012 Jul 18
5
Any comment on adding #cast and #cast! to ActiveRecord::Relation?
...erever 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 postgres columns only when there is no OID info f...