Guest User

Untitled

a guest
May 20th, 2018
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.66 KB | None | 0 0
  1. ## the problem
  2. class AuditLog < ActiveRecord::Base
  3. belongs_to :developer, :validate => true
  4. belongs_to :unvalidated_developer, :class_name => 'Developer'
  5. end
  6.  
  7.  
  8. log = AuditLog.new(:message => "")
  9.  
  10. log.developer = 1
  11. log.unvalidated_developer = 2
  12.  
  13. # log.developer_id is 1.
  14.  
  15. ## source of discovery:
  16. class ForumPost < ActiveRecord::Base
  17. belongs_to :author, :class_name => "User"
  18. end
  19.  
  20. class ForumThread < ActiveRecord::Base
  21. has_many :forum_posts
  22. attr_accessor :body, :author
  23. after_create :create_initial_post
  24.  
  25. def create_initial_post
  26. post = forum_posts.new(:body => body, :author => author)
  27. # omg post.user_id is nil!
  28. end
  29. end
Add Comment
Please, Sign In to add comment