Guest User

Untitled

a guest
May 24th, 2018
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.49 KB | None | 0 0
  1. ## transaction.rb
  2. class Transaction < ActiveRecord::Base
  3. has_one :seller_agent
  4. has_one :agent, :through => :seller_agent
  5. end
  6.  
  7. ## seller_agent.rb
  8. class SellerAgent < ActiveRecord::Base
  9. belongs_to :agent
  10. belongs_to :transaction
  11. end
  12.  
  13. ## agent.rb
  14. class Agent < ActiveRecord::Base
  15. has_many :seller_agents
  16. has_many :transactions, :through => :seller_agents
  17. end
  18.  
  19. ## summary of ./script/console output
  20. Loading development environment (Rails 2.1.1)
  21. >> tr = Transaction.new
  22. => #<Transaction id: nil, trans_number: nil, created_at: nil, updated_at: nil>
  23. >> tr.trans_number = 2221
  24. => 2221
  25. >> tr.save
  26. => true
  27. >> tr.agent
  28. >> ag = Agent.new
  29. => #<Agent id: nil, username: nil, created_at: nil, updated_at: nil>
  30. >> ag.username = 'justme'
  31. => "justme"
  32. >> ag.save
  33. => true
  34. >> tr.agent = ag
  35. => #<Agent id: 1, username: "justme", created_at: "2008-10-15 01:47:36", updated_at: "2008-10-15 01:47:36">
  36. >> tr.agent
  37. => nil
  38. >> tr.save
  39. => true
  40. >> tr.agent
  41. => nil
  42. >> tr.seller_agent
  43. => nil
  44. >> SellerAgent.find :all
  45. => []
  46. >> sa = SellerAgent.new
  47. => #<SellerAgent id: nil, agent_id: nil, transaction_id: nil, created_at: nil, updated_at: nil>
  48. >> sa.agent = ag
  49. => #<Agent id: 1, username: "justme", created_at: "2008-10-15 01:47:36", updated_at: "2008-10-15 01:47:36">
  50. >> sa.transaction = tr
  51. => #<Transaction id: 1, trans_number: 2221, created_at: "2008-10-15 01:46:22", updated_at: "2008-10-15 01:46:22">
  52. >> sa.transaction
  53. => #<Transaction id: 1, trans_number: 2221, created_at: "2008-10-15 01:46:22", updated_at: "2008-10-15 01:46:22">
  54. >> sa.save
  55. => #<Transaction id: 1, trans_number: 2221, created_at: "2008-10-15 01:46:22", updated_at: "2008-10-15 01:46:22">
  56. >> sa
  57. => #<SellerAgent id: nil, agent_id: 1, transaction_id: 1, created_at: nil, updated_at: nil>
  58. >> sa.save
  59. => #<Transaction id: 1, trans_number: 2221, created_at: "2008-10-15 01:46:22", updated_at: "2008-10-15 01:46:22">
  60. >> tr.seller_agent
  61. => nil
  62. >> tr.agent
  63. => nil
  64. >> tr = nil
  65. => nil
  66. >> tr = Transaction.find :first
  67. => #<Transaction id: 1, trans_number: 2221, created_at: "2008-10-15 01:46:22", updated_at: "2008-10-15 01:46:22">
  68. >> tr.agent
  69. => nil
  70. >> tr.seller_agent
  71. => nil
  72. >> sa
  73. => #<SellerAgent id: nil, agent_id: 1, transaction_id: 1, created_at: nil, updated_at: nil>
  74. >> sa.transaction
  75. => #<Transaction id: 1, trans_number: 2221, created_at: "2008-10-15 01:46:22", updated_at: "2008-10-15 01:46:22">
  76. >> sa.agent
  77. => #<Agent id: 1, username: "justme", created_at: "2008-10-15 01:47:36", updated_at: "2008-10-15 01:47:36">
Add Comment
Please, Sign In to add comment