class Book < ActiveRecord::Base
belongs_to :owner, polymorphic: true
end
class User < Active record::Base
has_many :books, as: :owner
end
Now the Book has three fields - name, owner_id and owner_type
. Now I need to search for the name of the user through books.
Something like this ..
Book.includes(:user).where("user_name LIKE ?","bla")
can anyone help me this?