Guest User

Untitled

a guest
Feb 21st, 2018
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.76 KB | None | 0 0
  1. # using merb console
  2.  
  3. >> user = User.get(1)
  4. ~ SELECT `id`, `login`, `email`, `image`, `created_at`, `updated_at`, `crypted_password`, `salt` FROM `users` WHERE (`id` = 1) ORDER BY `id` LIMIT 1
  5. => #<User id=1 login="mitkok" email=nil description=<not loaded> image=nil created_at=#<DateTime: 13255947691/5400,1/12,2299161> updated_at=#<DateTime: 13255947691/5400,1/12,2299161> crypted_password="132dd5baa9b6f8a6b2e85b3fd439aac99263f85d" salt="11a0b1b5cd533613d8b961d18ad5276ca865d8d9">
  6.  
  7. >> user.categories
  8. ~ SELECT `categories`.`id`, `categories`.`name`, `categories`.`url`, `categories`.`created_at`, `categories`.`updated_at` FROM `categories` INNER JOIN `categories_users` ON (`categories`.`id` = `categories_users`.`category_id`) WHERE (`categories_users`.`user_id` = 1) GROUP BY `categories`.`id`, `categories`.`name`, `categories`.`url`, `categories`.`created_at`, `categories`.`updated_at` ORDER BY `categories`.`id`
  9. => []
  10.  
  11. >> cat = Category.new
  12. => #<Category id=nil name=nil description=nil url=nil created_at=nil updated_at=nil>
  13.  
  14. >> cat.name = 'Homeless dogs'
  15. => "Homeless dogs"
  16.  
  17. >> cat.description = 'Really dirty and dangerous!'
  18. => "Really dirty and dangerous!"
  19.  
  20. >> user.categories << cat
  21. ~ INSERT INTO `categories` (`name`, `updated_at`, `description`, `created_at`) VALUES ('Homeless dogs', '2008-12-05 15:26:08', 'Really dirty and dangerous!', '2008-12-05 15:26:08')
  22. ~ SELECT `category_id`, `user_id` FROM `categories_users` WHERE (`user_id` IN (1)) ORDER BY `category_id`, `user_id`
  23. => [#<Category id=3 name="Homeless dogs" description="Really dirty and dangerous!" url=nil created_at=#<DateTime: 13255952723/5400,1/12,2299161> updated_at=#<DateTime: 13255952723/5400,1/12,2299161>>]
  24.  
  25. # Here category is created, but the association in table categories_users not.
Add Comment
Please, Sign In to add comment