Incorporate Cart's relations into ActiveRecord logic #414
Description
This is a thought, not a critical issue.
Currently, Cart
exists outside of the logical ActiveRecord relations (has_many :cart_reservations, belongs_to :user
) because it is never stored in a database. Consequently, the application logic is confusing to work with and maintenance is hard. (It is also possible that the application is to vulnerabilities. For example, no methods that use @cart.items
, which is an array of CartReservation.id
fields, ever check if @cart.reserver == CartReservation.reserver
before applying changes to all @cart.items
.)
This RailsCast episode and this StackOverflow topic suggest a way to take advantage of ActiveRecord without the database connection.
Alternatively, the Cart logic could be preserved but be included in User
model, with appropriate has_many :cart_reservations
designation. This would work, as we anticipate 1-to-1 relation between User
and Cart
anyway.
Activity