How to get list of books that is not borrowed and with stock
Anyone who can help me solve my problem on querying available books? I dont want to allow user to borrow book that is already borrowed or not yet returned and book that out of stock based on the number of copies. I have Book model and books table with number_of_copy column, I have BorrowRequest model and borrow_requests tables with details of borrower or user, and I have BorrowRequestItem model and borrow_request_items table with quantity column which is the number of copy borrowed by the user, and returned_at column to trigger if returned or not. Now I want to query the books that is now borrowed by the user and books with stock.