I am trying to query model table:
> messages = Message.find_by_sql("select count(*) as messages_count,
> sender_id, recipient_id, min(is_read) as is_read from messages group
> by sender_id, recipient_id")
DB table contains fields sender_id, recipient_id, is_read. As the result I've got an arrays of hashes where messages_count is not present.
I tried in my
class Message < ActiveRecord::Base
def attributes
super.merge('messages_count' => self.messages_count)
end
after_initialize do
self.messages_count = nil unless @attributes.key?("messages_count")
end
also I tried to override get hash like this
def serializable_hash(options = {})
end
this was not triggered.
What can I try else? Thanks!