Hi, I'm trying to use transactions in my code but I'm experiencing
some difficulties.

My code looks like this:

post "/article/new" do
        @user = User.get(session[:uid])
        @qty = params[:qty].to_i

        DataMapper.repository(:default).transaction do
                @article = Article.create(params[:article])
                @article.stock_line = StockLine.create(
                        :work_center => default_work_center,
                        :units => @qty,
                        :available => @qty
                )
        end

        if @article.saved?
                @status = "Ok"
                @article = Article.new
        else
                @status = "ERROR"
        end

        erb :"article/new"
end

When I execute the code on my browser (this is a sinatra app), I get
the following error:

No method "saved?" for Nil Class

So I assume that @article only exists inside the transaction object.
So I tried creating the object in the outside with this:

     @article = Article.new(params[:article)

     DataMapper.repository(:default).transaction do
          @article.save
          .....
     end

In that case, @article.saved? always returns False.

What am I doing wrong? How can I check if an entire transaction has
failed?

Thanks

-- 
You received this message because you are subscribed to the Google Groups 
"DataMapper" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/datamapper?hl=en.

Reply via email to