Advertisement
Guest User

Untitled

a guest
Nov 27th, 2014
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.89 KB | None | 0 0
  1. model.columns.each do |val|
  2. # i got now:
  3. # val == key
  4. # model[val] == value
  5. myPrint(val , model[val])
  6. end
  7.  
  8. class Sequel::Model
  9. # helper method to get {:keys=>:accessors}
  10. def self.assoc_list
  11. res = Hash.new
  12. association_reflections.each do |k,v|
  13. res[v[:key]] = k
  14. end
  15. return res
  16. end
  17. end
  18.  
  19. class Unittype < Sequel::Model(:unittypes)
  20. end
  21.  
  22. class Unit < Sequel::Model(:units)
  23. many_to_one :unittype
  24. end
  25.  
  26.  
  27. #trying to print Units
  28.  
  29. Unit.all.each do | u |
  30. Unit.columns.each do | col |
  31. if Unit.assoc_list.key?(col)
  32. key = Unit.assoc_list[col]
  33. # ok, now i got key == :unittype
  34. # and want to get value = Unit.key.name (Unit.unittype.name)
  35. value = ???
  36.  
  37. MyPrint(key,value)
  38. else
  39. # key, value
  40. MyPrint(col,u[col])
  41. end
  42. end
  43. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement