Advertisement
Guest User

Untitled

a guest
Mar 29th, 2017
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.49 KB | None | 0 0
  1. #Simple monkey patch would work
  2.  
  3. module ActiveRecord
  4. Base.send :attr_accessor, :_row_
  5.  
  6. module Associations
  7. class JoinDependency
  8. JoinBase && class JoinPart
  9. def instantiate_with_row(row, *args)
  10. instantiate_without_row(row, *args).tap { |i| i._row_ = row }
  11. end
  12. alias_method_chain :instantiate, :row
  13. end
  14. end
  15. end
  16. end
  17.  
  18. #Then you can get a column value from a row:
  19.  
  20. Post.includes(:comments).select("posts.*, 1 as testval").first._row_['test_val']
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement