Tuesday, October 13, 2009

[Rails] Re: Using transaction in non-active record model

Andrew Pace wrote:
> Sorry about above. The post should be:
>
> I want to use logical models to aggregate data to present information
> to the user. For example, I might have a controller that looks like
> the following:
>
> class OrdersController < ApplicationController
> def new
> @order = Order.new
> @address = Address.new
> end
> end
>
> What I would prefer to have is:
>
> class OrdersController < ApplicationController
> def new
> @logical_order = LogicalOrder.new
> end
> end
>
> Logical Order would look like (NOT and ActiveRecord model):
>
> class LogicalOrder
> def order
> @order ||= Order.new
> end
>
> def address
> @address ||= Address.new
> end
>
> def save
> address_saved = address.save
> order_saved = order.save
> address_saved && order_saved
> end
> end
>
[...]
> Since this model is not an
> active record model, how can I implement the save method such that it
> is wrapped in a transaction. I have thought about pushing the save
> logic back into one of the active record models (like the Order
> model), but I would prefer to do it within this class. Any thoughts?

Just call the transaction from within your LogicalOrder code. What's the
problem?

>
> Thanks,
>
> Andrew

Best,
--
Marnen Laibow-Koser
http://www.marnen.org
marnen@marnen.org
--
Posted via http://www.ruby-forum.com/.

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate