Freezing related objects

Does anyone know of a method in Rails with which a related object can be frozen. The problem I am facing is that I have an order model with many line items, which, in turn, are related to a product or service. When the order is paid, I need to freeze the details of the ordered items, so that when the price changes, the order amounts are saved.

+3
source share
3 answers

I used to work on an online purchasing system. What you want to do is the Order class and the LineItem class. LineItems stores product data, such as price, quantity, and possibly some other information needed for recording. This is harder, but this is the only way to find out the details.

An order simply consists of LineItems and probably contains the shipping and billing addresses. The total value of the order can be calculated by adding LineItems.

Basically, you freeze data before a person makes a purchase. When they are added to the order, the data is frozen because LineItems duplicates nessacary information. That way, when a product is removed from your system, you can still understand old orders.

, rails "AASM" (, ), .

: AASM http://github.com/rubyist/aasm/tree/master

+8

:

1) . . , , -, , , . :version_number find_latest_course(course_id), , . "" , , , . (, , LineItems item_id item_version_number.)

, , , .

2) LineItem LineItem . , has_a , , . "LineItem" , -, LineItem , -. InventoryItem#current_price , LineItems.

3) , . - , , , . , .

" 6 . , ? , , ? , !"

+3

, ? , , , 1 , , , 5 , .

: , , . , , . , , ..

, , . , , . - .

+1

Source: https://habr.com/ru/post/1699508/


All Articles