You can use author_id: integer
Then in your user model:
has_many :books, foreign_key: :author_id, class_name: "Book", dependent: :nullify
I use dependency :: nullify to avoid errors when deleting a record, but you can use depend :: destroy if you need to destroy books when you destroy a user.
And the book model:
belongs_to :user, foreign_key: :author_id, class_name: 'User'
You should add an index to this column.
source share