title: How to access belongs_to model in class method that is called from the belongs_to model
body: <p>There are <code>User</code> and <code>Book</code> model, a user has many books and a book belongs to a user.</p>
  <p>The <code>Book</code> has a class method <code>create_from_hash</code> and the method is called from <code>User</code> model.</p>
  <pre><code>class User &lt; ApplicationRecord
    has_many :books
  
    def create_book
      book_hash = {title: 'foo'}
      books.create_from_hash(book_hash)
    end
  end
  
  class Book &lt; ApplicationRecord
    belongs_to :user
    def self.create_from_hash(book_hash)
      # NameError: undefined local variable or method
      p user_id 
    end
  end
  </code></pre>
  <p>How can I get <code>user_id</code> or <code>user</code> instance from the class method?</p>