Conversation
|
Please add a proper title. It's practically a short gist of what's being done, shorter than the description. |
I'll make sure to do so on future PR's. thank you for reminding! |
app/models/book.rb
Outdated
| validates :cover_image_url, presence: true | ||
| end No newline at end of file | ||
|
|
||
| alias_attribute :book_id, :id |
There was a problem hiding this comment.
What's this for? Why is the primary id of the Book table called book_id?
There was a problem hiding this comment.
this is for the Book component in the frontend, which is being used by three other components. it initially looked like this

where in the Discover component, the books are from the Book controller itself so the 'id' there in the addToList() would refer to the book itself.
whereas in the ReadingList/FinishedList components, the books come from the UserBook controller, so the 'id' in the markBook() and removeBook() refers to the UserBook.
I thought this would be confusing if someone else read the code thats why I opted to change the names
Now that I think about it though, it was unecessary to use the alias on the book model itself since Book.id would make a lot more sense in the frontend and the one that actually needs to be aliased would be the UserBook id, that way it will read as Book.user_book_id
Am I on the right track here? or is there a better way of doing this
removed book_id alias
updated rspec files
|
Approving just to remove this from my PR list :D |
so I made a seperate serializer for when the data is just a single object because it needs to be handled differently.
I tried making a serializer function with an 'if-block' or a ternary function that would accept any data and act accordingly but I was unsuccessful.
please let me know if there is a better way to do this.
also added attribute aliases for readability when it comes to the frontend