In one table I have a list of book selections by readers. Each row represents a book and a user. When multiple user select the same book, there are multiple rows added. Works fine. I have created a roll-up table that counts how many times each book is in the books table.
I cannot figure out how to add the book to the roll-up table at the same time it is added to the books table without creating redundant rows in the roll-up table. The logic would be something like, “if book already exists in roll-up, do nothing, else, add book to roll-up table.”
Okay, so what you could do is add a relation column to the table that is the source of the collection, that matches the book with the books column in your rollup table. Then use the state of that relation to decide what to do. If it’s empty, add a row to your rollup table, otherwise don’t.
Book is added to the books table AFTER the click, then the relation logic you describe can work. Best I can tell, IF logic can only be inserted at the top of the action list, not after an action. Maybe I am wrong?
The book has to be in the books table in order for the relation to work. Upon clicking a book, the action currently adds a row to the books table. Now, the relation is there. I dont think the relation approach works unless there is a book in the table. I may have to rethink all of this.
You said that you are presenting a list of books in a collection. Where does that list come from?
Where ever it is, that’s where you need the relation.
User enters book title and Google Books API returns any titles that are close. These are displayed in a collection list. Action is set up so that upon click of a title, a row is added to the books table.
The table with the results from the API is where the relation should be. Doesn’t really matter what’s been added to the Books table, since it’s unique to each user. You are trying to determine if a book has been added to the Rollup table. The relation from the API list to the Rollup table will tell you that. Since the action should be using the API list then that’s where the relation should be.