Mark Reginald James wrote:
Constantin Gavrilescu wrote:
code in ction_controller/session_management.rb and
clear_persistent_model_associations() takes care of removing
Any suggestions on how to handle this?
You can serialize and deserialize the whole structure with
to_json and from_json, specifying the includes.
Marshal dump() and load() saves associated objects, too. Is there some
specific reason why I should use json?
Maybe I need to explain what I want to achieve. I have an order with a
multitude of associated associations which, to further complicate
things, have more associations, like extra charges.
order has many containers
container has many extra charges
The user edits the order, adds or deletes containers, adds or deletes
extra charges to the containers. The problem is that I want all the
changes to be saved the the user presses the "Save order" button, not
when he adds or edits each container or extra charge. I wanted to save
the whole order and associations in the session until it's ready to save
in one atomic operation, but it seems there's no easy way to do this
with the way Rails and ActiveRecord works.
?> o = Order.find(20)
=> #<ImportOrder:0x46b3934 @attributes=....
o.containers = Hash.new #This will delete all containers in the database, not just in the memory.
So when I work with activerecord objects, they might get commited to the
database when I don't really want that.