Guest User

Untitled

a guest
Aug 15th, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.65 KB | None | 0 0
  1. Rails difference in object created from a .find(:id) and .where() methods
  2. tec = Technique.find(6)
  3. tec2 = Technique.where(:korean => 'Jok Sul')
  4.  
  5. tec2 = Technique.where(:korean => 'Jok Sul').first
  6.  
  7. tec_scope = Technique.where(:korean => 'Jok Sul') # create an internal query
  8.  
  9. tec_scope.all # returns array
  10. tec_scope.first # retuns one element
  11.  
  12. tec_objects = Technique.find(6) # explicitly runs a query and returns one object (in this case)
  13.  
  14. Technique.find([4,5]) # will return an array
  15. Technique.find(4) # will return one object
  16. Technique.where(:some_key => "some value").all # will return an array
  17. Technique.where(:id => 5).first # will return one object
Add Comment
Please, Sign In to add comment